golang / go

The Go programming language
https://go.dev
BSD 3-Clause "New" or "Revised" License
121.12k stars 17.37k forks source link

proposal: x/net/websocket: Add proxy support #63205

Open dmytro-i opened 9 months ago

dmytro-i commented 9 months ago

I'd like to add proxy support to websocket.

In the client.go there is NewClient function which I think I need to change to add support for connection through proxy. The way I see it is to add something along the lines of

    if (config.Proxy != nil) {
        err = newProxyConn(config.Proxy)
                if err != nil {
            return
            }
    }

before err = hybiClientHandshake(config, br, bw) call. Function newProxyConn will basically send a CONNECT request to the proxy server and then websocket will proceed. This of course will require Proxy to be added to Config struct.

This seems too easy to be true. I'm new to golang and probably missing something. All comments and suggestions are welcome.

ianlancetaylor commented 9 months ago

Can you outline the user visible changes? Is it just a new Config.Proxy field? Thanks.

dmytro-i commented 9 months ago

Yes, that should be it. I can try copying websocket source files into my project and playing with it to see if it works.

fortuna commented 1 month ago

There's no need to add proxy support to the websocket package. You can already use a proxy.

Dial the destination using your proxy, then call websocket.NewClient on the connection.

Adding explicit proxy support will unnecessarily bloat the package.