java - 使用 ResponseBuilder 强制位置标头中的相对 URI
问题描述
我正在使用 ResponseBuilder 类发送重定向响应
responseBuilder.header("Location", "/foo");
我的问题是 URI 解析为绝对 URI。根据文档:
如果提供了相对 URI,它将通过相对于应用程序的基本 URI 解析它来转换为绝对 URI(请参阅 UriInfo.getBaseUri())。如果为 null,任何现有的位置值都将被删除。
因为我的服务在反向代理后面运行,所以位置值的主机名错误。返回位置标头时,有什么方法可以强制使用相对 URI?
解决方案
You can use X-Forwarded-For
and X-Forwarded-Host
to specify the original client or host behind a load-balancer or a reverse proxy.
Host names and ports of reverse proxies (load balancers, CDNs) may differ from the origin server handling the request, in that case the X-Forwarded-Host header is useful to determine which Host was originally used.
推荐阅读
- javascript - 如何在 Div 中显示谷歌地图缩放级别
- r - 在 MARSS 函数中估计 G 矩阵
- java - 如何以弹簧形式计算带有变量的textarea?
- java - java Jackson Mapper - 嵌套属性
- ios - 如何从 HealthKit 获得每天的正念时间?
- javascript - TypeError:调度不是嵌套组件中的函数
- android - 主源集中的重构不会传播到非活动的构建变体
- c++ - 如何使用枚举实例化模板构造函数
- architecture - Flutter - Scoped BloCs 问题
- excel - 在excel上标记过期日期(有点复杂)