简体   繁体   English

如何在REST应用程序中获取“ X-Forwarded-Proto”标头?

[英]How to obtain “X-Forwarded-Proto” header in REST application?

I have a REST application running on tomcat. 我在Tomcat上运行了一个REST应用程序。 I am forwarding http requests to https using server.xml redirectPort parameter. 我正在使用server.xml redirectPort参数将http请求转发到https。

Now, on the server side, I want to read the X-Forwarded-Proto header to identify if requests are being redirected. 现在,在服务器端,我想读取X-Forwarded-Proto标头,以确定请求是否被重定向。

My code looks like this: 我的代码如下所示:

@Context
UriInfo uriInfo;

@Context
Request request;

protected Response checkRedirect(SecurityContext sc)
{

   String forwardedProtocol = ((ContainerRequest)request).getHeaderValue("X-Forwarded-Proto");

}

However, this does not work. 但是,这不起作用。 It seems like the request object only gives access to handful of http headers. 似乎request对象仅允许访问少数http标头。

Can someone please suggest the best way I can obtain the header value? 有人可以建议我获取标头值的最佳方法吗? Thanks in advance. 提前致谢。

您需要指示 tomcat注意。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM