我正在通过Apache NiFi过渡使用OkHttp.我试图确定如何在重定向时处理授权和其他敏感标头.关于重定向,NiFi的InvokeHTTP处理器与OkHttp的唯一交互是here,它读取处理器属性并在OkHttpClientBuilder对象上设置选项:
// Set whether to follow redirects
okHttpClientBuilder.followRedirects(context.getProperty(PROP_FOLLOW_REDIRECTS).asBoolean());
正如我所期望的那样,我快速搜索了OkHttp的来源,似乎无法确定重定向的位置以验证是否从后续请求中删除了授权.出于安全原因,cURL只是该行为的recently adopted.
解决方法:
它发生在RetryAndFollowUpInterceptor.
// When redirecting across hosts, drop all authentication headers. This
// is potentially annoying to the application layer since they have no
// way to retain them.
if (!sameConnection(userResponse, url)) {
requestBuilder.removeHeader("Authorization");
}