Create a TLS connection using a http/https proxy?

I’ve this really simple bit of code.

conn, err := tls.Dial("tcp", fmt.Sprintf("%s:%d", *server, *port), &tls.Config{})
 if err != nil {
  panic("failed to connect: " + err.Error())
 }
 // Get the ConnectionState struct as that's the one which gives us x509.Certificate struct
 connectionState := conn.ConnectionState(

How do we get the conn.ConnectionState object when I’ve to go via a HTTP proxy? I tried looking at tls.Config struct but it doesn’t contain anything helpful.

Thanks in advance.

Using a Proxy does not have anything to do with TLS. A TLS Connect happens after the actual connection has been made. You need to look at using a Proxy with a normal HTTP client. I think you need to specify your own Transport. This Stack Overflow should be helpful http://stackoverflow.com/questions/14661511/setting-up-proxy-for-http-client

It says to do something like this

proxyUrl, err := url.Parse("http://proxyIp:proxyPort")
myClient := &http.Client{Transport: &http.Transport{Proxy: http.ProxyURL(proxyUrl)}}

I might be wrong, I have never used a proxy in Go before.

1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.