在Undertow中将HTTP重定向到HTTPS [英] Redirect HTTP to HTTPS in Undertow
问题描述
如何在Undertow中配置HTTP-> HTTPS重定向?我查看了Undertow的代码库,有些类似乎是相关的(例如RedirectHandler)。另外,Undertow文档(预测属性和处理程序)似乎正好针对这一点其中的问题。但是我不确定从哪里开始。
How can one configure HTTP->HTTPS redirection in Undertow? I've looked through Undertow's codebase, there are some classes that seem to be relevant (e.g. RedirectHandler). Also, Undertow documentation (Predicates Attributes and Handlers) seems to target exactly this problem among others. But I'm not sure where to start.
基本上,我正在寻找的是Apache的mod_rewrite配置的一些对应物:
Basically, what I'm looking for is some counterpart to Apache's mod_rewrite configuration:
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
谢谢!
推荐答案
此答案指出正确的方向。以编程方式,必须将 SecurityConstraint
添加到 Builder
并设置 ConfidentialPortManager
:
This answer pointed in the right direction. Programmatically, one has to add a SecurityConstraint
to Builder
and set ConfidentialPortManager
:
DeploymentInfo servletBuilder = Servlets.deployment();
servletBuilder.addSecurityConstraint(new SecurityConstraint()
.addWebResourceCollection(new WebResourceCollection()
.addUrlPattern("/*"))
.setTransportGuaranteeType(TransportGuaranteeType.CONFIDENTIAL)
.setEmptyRoleSemantic(EmptyRoleSemantic.PERMIT))
.setConfidentialPortManager(new ConfidentialPortManager() {
@Override
public int getConfidentialPort(HttpServerExchange exchange) {
return 443;
}
}
);
这篇关于在Undertow中将HTTP重定向到HTTPS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!