gorilla / websocket

Package gorilla/websocket is a fast, well-tested and widely used WebSocket implementation for Go.

Home Page:https://gorilla.github.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Why does specifying the proxy address not work?

stricklandye opened this issue · comments

Is there an existing issue for this?

  • I have searched the existing issues

Current Behavior

Hi there.
I want to specify proxy address for websocket connection instead of setting environment variables http_proxy and https_proxy. I copied code from#107 and it's like:

dg.Dialer = &websocket.Dialer{
  Proxy: http.ProxyURL(&url.URL{
	  Scheme: "http", // or "https" depending on your proxy
	  Host:   "localhost:7890",
  }),
}

I have also tried to use https but it still doesn't work. However, if use http_proxy and https_proxy env variables with http.ProxyFromEnvironment, it works fine. code snippet:

os.Setenv("http_proxy", "http://localhost:7890")
os.Setenv("https_proxy", "http://localhost:7890")
os.Setenv("HTTP_PROXY", "http://localhost:7890")
os.Setenv("HTTPs_PROXY", "http://localhost:7890")
dg, err := discordgo.New("Bot " + botToken)
dg.Dialer = &websocket.Dialer{
   Proxy: http.ProxyFromEnvironment,
}

Expected Behavior

I want to specify proxy address for websokct addres instead of setting environment variables http_proxy and https_proxy. Because it affects other http connection that don't want to go through the proxy.

Steps To Reproduce

No response

Anything else?

I am using discordgo which uses this repo inside. So it maybe not a right place to open the issue here. Hope someone could explain why setting proxy for Dialer does not work as I expect.