从9.4号码头开始。?可以在同一端口上运行http和https。其要点是:
HttpConnectionFactory http = new HttpConnectionFactory();
SslConnectionFactory https = new SslConnectionFactory(sslCtxFactory, http.getProtocol());
DetectorConnectionFactory conFactory = new DetectorConnectionFactory(https);
ServerConnector connector = new ServerConnector(server, conFactory, http);
因为我只想提供https,我想重定向每一个 http://host:port/stuff
至 https://host:port/stuff
. 我知道如何用 RedirectRule
或者只是和一个叫early的人。
我正在努力解决的问题是:如何从请求中找出连接是http而不是https?
当我看着 Request
在调试器中,我没有发现任何提示,所有的东西看起来都像是http,即使连接是https, Request.isSecure()
是假的,计划是假的 http
等等。我能想到的最好的办法是:
if (Request.getHttpChannel().getEndPoint() instanceof SslConnection.DecryptedEndPoint())
下面是一个带注解和剪裁的堆栈跟踪,显示了我的处理程序是如何相互 Package 的:
at server.HttpToHttpsRedirectRule.matchAndApply(HttpToHttpsRedirectRule.java:34)
"^^ Here I do the matchAndApply myself and then use a jetty RedirectRule.apply"
"The redirect works OK, but figuring whether it is HTTPS does not work"
at org.eclipse.jetty.rewrite.handler.RuleContainer.apply(RuleContainer.java:166)
at org.eclipse.jetty.rewrite.handler.RuleContainer.matchAndApply(RuleContainer.java:145)
at org.eclipse.jetty.rewrite.handler.RewriteHandler.handle(RewriteHandler.java:317)
at org.eclipse.jetty.server.handler.gzip.GzipHandler.handle(GzipHandler.java:766)
at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:127)
at server.LogHandler.handle(LogHandler.java:33)
at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:127)
"^^^ the outermost handler"
[clip]
at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:380)
"^^^ we decoded the ssl and feed the lower levels plain HTTP"
[clip]
at org.eclipse.jetty.io.ssl.SslConnection$1.run(SslConnection.java:146)
"^^^ we are in SSL"
它在我的房间里 HttpToHttpsRedirectRule
我想找出哪一个连接。有比这更明智的解决办法吗 instanceof
上面提到的?
暂无答案!
目前还没有任何答案,快来回答吧!