godnshttp-proxy

How does Go handle DNS requests when using a HTTP proxy?


When you configure a http.Client in Go with a HTTP proxy, how does Go handle the DNS request?

I suspect that the name resolved is locally, then the request is proxied.

Is that correct? Or is the DNS request also somehow proxied through?

    proxiedClient := &http.Client{
        Transport: &http.Transport{
            Proxy: http.ProxyURL(proxyURL),
        },
    }

Solution

  • When a HTTP proxy is involved the client gets the IP of the proxy in order to connect to the proxy, but the domain from the target URL is resolved by the proxy. This is not specific to Go, but how HTTP proxies work. And it makes sense this way since the proxy might resolve the domain differently than the original client depending on the connectivity options the proxy has, like choice of IPv4 vs IPv6.

    The same is true for Socks5 proxy. It would not by true for Socks4 proxy since this protocol requires the IP address of the target (and only supports IPv4). But Socks4 does not seem to be supported here.