没有为CONNECT请求调用Servlet service()方法 [英] Servlet service() method not getting called for CONNECT requests

查看:109
本文介绍了没有为CONNECT请求调用Servlet service()方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用Servlet 3.0在Jetty中编写转发代理.

I am trying to write a forward proxy in Jetty using Servlet 3.0.

我有一个简单的代码-

public class testServlet extends HttpServlet {

   @Override
    protected  void service (HttpServletRequest req, HttpServletResponse resp) throws   ServletException, IOException {
       System.out.println(req.toString());        

  }

}

如果客户端请求HTTP站点,则会调用上述服务方法,但是当请求HTTPS站点(使用HTTP Connect方法)时,不会调用上述方法.为什么?

If client requests a HTTP site, above service method gets called but when HTTPS site is requested (using HTTP Connect method), above method is not being called. Why?

我显然可以使用Jetty的处理程序,但我更喜欢使用servlet,以便代码保持一定的可移植性(我可以在Glassfish,Tomat,Jetty等环境下运行它)

I can obviously use Jetty's handlers but I would rather prefer to use servlet so that code remains somewhat portable (I can run it under Glassfish, Tomat, Jetty etc)

你知道什么地方可能出问题吗?

Any idea what might be wrong?

推荐答案

可以向Servlet服务方法传递CONNECT请求,但是这样做最终是徒劳的,因为无法处理Servlet内部的CONNECT. .您实际上没有访问原始IO流的权限,只有访问请求/响应的HTTP内容的权限.您几乎可以完成他的工作,但是效率却很高(没有异步IO等),因此最终您最终还是会退回到Jetty API.

It is possible to deliver a CONNECT request to a Servlet service method, but it is ultimately futile to do so because it is impossible to handle a CONNECT inside a servlet. You don't really have access to the raw IO streams, only the HTTP content of the request/response. You can almost make his work, but never efficiently (no async IO etc.) So ultimately you will end up falling back to Jetty APIs anyway.

此外,为什么不仅仅建立在Jetty已经提供的支持上呢?

Also, why not just build on the support already provided by Jetty:

http://download. eclipse.org/jetty/stable-9/xref/org/eclipse/jetty/proxy/ConnectHandler.html http://download.eclipse.org /jetty/stable-9/xref/org/eclipse/jetty/proxy/ProxyServlet.html

这篇关于没有为CONNECT请求调用Servlet service()方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆