Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Client attempts to connect to localhost:80 instead of set target host when using proxy #126

Closed
utwyko opened this issue Jul 6, 2017 · 1 comment
Milestone

Comments

@utwyko
Copy link
Contributor

utwyko commented Jul 6, 2017

I'm trying to use a proxy with a simple HTTP client, but I'm getting a ProxyConnectException that indicates that the proxy is attempting to connect to localhost rather than the actual target host.

The code:

 private static final HttpClient httpClient = HttpClient.create(ops ->
            ops
                    .connect("jsonplaceholder.typicode.com", 80)
                    .proxy("138.197.86.57", 3128));

    public Mono<String> getString() {
        return httpClient.get("/posts", request ->
                request
                        .addHeader(HttpHeaders.ACCEPT, MediaType.APPLICATION_JSON_VALUE))
                .then(response -> response.receive().aggregate().asString());
    }

The exception:

io.netty.handler.proxy.ProxyConnectException: http, none, /138.197.86.57:3128 => localhost:80, status: 403 Forbidden
    at io.netty.handler.proxy.HttpProxyHandler.handleResponse(HttpProxyHandler.java:146) ~[netty-handler-proxy-4.1.9.Final.jar:4.1.9.Final]
    at io.netty.handler.proxy.ProxyHandler.channelRead(ProxyHandler.java:260) ~[netty-handler-proxy-4.1.9.Final.jar:4.1.9.Final]
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) [netty-transport-4.1.9.Final.jar:4.1.9.Final]
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) [netty-transport-4.1.9.Final.jar:4.1.9.Final]
    at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340) [netty-transport-4.1.9.Final.jar:4.1.9.Final]
    at io.netty.channel.CombinedChannelDuplexHandler$DelegatingChannelHandlerContext.fireChannelRead(CombinedChannelDuplexHandler.java:438) [netty-transport-4.1.9.Final.jar:4.1.9.Final]
    at io.netty.handler.codec.ByteToMessageDecoder.fireChannelRead(ByteToMessageDecoder.java:293) [netty-codec-4.1.9.Final.jar:4.1.9.Final]
    at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:267) [netty-codec-4.1.9.Final.jar:4.1.9.Final]
    at io.netty.channel.CombinedChannelDuplexHandler.channelRead(CombinedChannelDuplexHandler.java:253) [netty-transport-4.1.9.Final.jar:4.1.9.Final]
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) [netty-transport-4.1.9.Final.jar:4.1.9.Final]
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) [netty-transport-4.1.9.Final.jar:4.1.9.Final]
    at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340) [netty-transport-4.1.9.Final.jar:4.1.9.Final]
    at io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1334) [netty-transport-4.1.9.Final.jar:4.1.9.Final]
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) [netty-transport-4.1.9.Final.jar:4.1.9.Final]
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) [netty-transport-4.1.9.Final.jar:4.1.9.Final]
    at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:926) [netty-transport-4.1.9.Final.jar:4.1.9.Final]
    at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:134) [netty-transport-4.1.9.Final.jar:4.1.9.Final]
    at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:624) [netty-transport-4.1.9.Final.jar:4.1.9.Final]
    at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:559) [netty-transport-4.1.9.Final.jar:4.1.9.Final]
    at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:476) [netty-transport-4.1.9.Final.jar:4.1.9.Final]
    at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:438) [netty-transport-4.1.9.Final.jar:4.1.9.Final]
    at io.netty.util.concurrent.SingleThreadEventExecutor$5.run(SingleThreadEventExecutor.java:858) [netty-common-4.1.9.Final.jar:4.1.9.Final]
    at java.lang.Thread.run(Thread.java:748) [na:1.8.0_131]
@simonbasle simonbasle changed the title Proxy attempts to connect to localhost:80 instead of set proxy address Client attempts to connect to localhost:80 instead of set target host when using proxy Jul 6, 2017
@simonbasle
Copy link
Contributor

Reproducible in pure reactor-netty. Without an actual proxy server, this is still visible in the DEBUG logs:

17:24:33.226 [reactor-http-nio-5] DEBUG r.ipc.netty.http.client.HttpClient - [id: 0x83702c9a] CONNECT: localhost:80
17:24:33.226 [reactor-http-nio-5] DEBUG reactor.ipc.netty.proxy - [id: 0x83702c9a] CONNECT: 138.197.86.57:3128

This seems to come from the fact that HttpClientOptions.formatSchemeAndHost always falls back to a localhost hostname if proxy is configured :(

simonbasle added a commit that referenced this issue Jul 6, 2017
This commit fixes the HttpClientOptions to correctly derive relative
urls from the base url, even when a proxy is configured. It would
previously wrongly replace the hostname with `localhost`.
simonbasle added a commit that referenced this issue Jul 6, 2017
This commit fixes the HttpClientOptions to correctly derive relative
urls from the base url, even when a proxy is configured. It would
previously wrongly replace the hostname with `localhost`.
@simonbasle simonbasle modified the milestone: 0.7.0.M1 Jul 6, 2017
simonbasle added a commit that referenced this issue Jul 10, 2017
This commit fixes the HttpClientOptions to correctly derive relative
urls from the base url, even when a proxy is configured. It would
previously wrongly replace the hostname with `localhost`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants