gorilla / websocket

Package gorilla/websocket is a fast, well-tested and widely used WebSocket implementation for Go.
https://gorilla.github.io
BSD 2-Clause "Simplified" License
22.06k stars 3.47k forks source link

Support custom HTTP headers for CONNECT proxy request #479

Open aus opened 5 years ago

aus commented 5 years ago

When an HTTP proxy is used, there is no way to customize the headers in the initial CONNECT request. In some situations, a HTTP proxy may require certain User-Agents or other headers. golang added support for this in net/http in 1.8. The golang issue is documented here with support added in 1.8 as documented here.

Note, this is not the same as providing a requestHeader to Conn.NewClient or Dialer.Dial. These headers are only present after the initial CONNECT request to the HTTP proxy.

garyburd commented 5 years ago

Fix this issue by adding a ProxyConnectHeader to Dialer and use this header connecting through a proxy.

Fenny commented 4 years ago

Untill this feature gets properly implemented into the main branch, you can use my version. https://github.com/fenny/websocket

dialer := websocket.Dialer{
  Proxy: http.ProxyURL(&url.URL{
    Scheme: "http",
    Host: "127.0.0.1:6969",
    Path: "/",
  }),
  ProxyConnectHeaders: map[string]string{
    "Proxy-Auth": "user:pass",
    "Proxy-Geo":  "EU",
  },
}