How to use a simple HTTP proxy with Reactor Netty client?

Viewed 3269

I'm trying to use a simple HTTP proxy to externally cache the responses. I tried the following snippet:

public static void main(String[] args) {
  HttpClient httpClient = HttpClient.builder().options(httpOptions -> {
    httpOptions.proxy(proxyOptions -> proxyOptions
        .type(Proxy.HTTP)
        .address(InetSocketAddress.createUnresolved("localhost", 7000))
    );
  }).build();
  String url = "http://httpbin.org/get";
  HttpClientResponse response = httpClient.get(url).block();
  System.out.println(response == null ? "null" : response.status().code());
}

... but the result is that the client starts with a CONNECT command, creating a TCP tunnel. When I work with curl, I do the following:

curl "http://httpbin.org/get" -x "localhost:7000"

... and it simply issues a regular HTTP request against the proxy.

My question: how do I use Raector-Netty to issue a regular (not a CONNECT based) request against a proxy?

1 Answers
    ReactorClientHttpConnector connector = new ReactorClientHttpConnector(options ->
            options.httpProxy(addressSpec -> {
                return addressSpec.host("http://proxy_server").port(proxy_port); }));

    webClient = WebClient.builder()
                         .clientConnector(connector)
                         .baseUrl(baseUrl)
                         .build();
Related