我正在使用spring-boot-starter-webflux 2.1.3.RELEASE中的 Spring WebClient来检查代理服务器的匿名级别。在我通过一些代理服务器使用 WebClient 向自定义 node.js http 服务器发出一些请求后,我的请求中没有与代理相关的 HTTP 标头。我错过了例如x-forwarded-for, via, x-proxy-id
..只是remote-address
暴露了。
据我了解,netty 客户端通过tcp CONNECT
每种代理类型(HTTP、SOCKS4/5)连接到代理,这就是缺少标头的原因。
问题: 有没有办法使用这种方法获取经典的代理 HTTP 标头,或者是否有另一种方法可以使用 WebClient 配置代理服务器?
我的示例配置:
HttpClient httpClient = HttpClient.create()
.tcpConfiguration(tcpClient ->
tcpClient
.proxy(proxy -> {
proxy.type(ProxyProvider.Proxy.HTTP).address(new InetSocketAddress(ip, port));})
.option(ChannelOption.CONNECT_TIMEOUT_MILLIS, 10000)
.doOnConnected(connection ->
connection
.addHandlerLast(new ReadTimeoutHandler(10000))
.addHandlerLast(new WriteTimeoutHandler(10000))));
ReactorClientHttpConnector connector = new ReactorClientHttpConnector(httpClient);
WebClient build = WebClient.builder()
.baseUrl(baseUrl)
.clientConnector(connector)
.build();
预期的标题
{"user-agent":"ReactorNetty/0.8.4.RELEASE","host":"21X.8X.XX.145:8XX","accept":"*/*","x-proxy-id":"719306848","x-forwarded-for":"21X.8X.XX.145","via":"1.1 101.XX.8X.11X (Mikrotik HttpProxy)"}
实际标题
{"user-agent":"ReactorNetty/0.8.4.RELEASE","host":"21X.8X.XX.145:8XX","accept":"*/*"}