我有一个REST应用程序在tomcat上运行。我正在使用server.xml redirectPort
参数将http请求转发到https。
现在,在服务器端,我想读取X-Forwarded-Proto标头,以确定请求是否被重定向。
我的代码如下:
@Context
UriInfo uriInfo;
@Context
Request request;
protected Response checkRedirect(SecurityContext sc)
{
String forwardedProtocol = ((ContainerRequest)request).getHeaderValue("X-Forwarded-Proto");
}
然而,这是行不通的。请求对象似乎只提供对少数http头的访问权限。
有人能建议我获得表头值的最佳方式吗?提前谢谢。
您需要指示tomcat注意。