Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is there socks5 support for websocket connections? #297

Closed
melnikalex opened this issue Nov 10, 2017 · 7 comments
Closed

Is there socks5 support for websocket connections? #297

melnikalex opened this issue Nov 10, 2017 · 7 comments
Assignees

Comments

@melnikalex
Copy link

Can gorilla establish websocket connections through a socks5 proxy?

If not, is there a plan to do so?

Thank you!

@garyburd
Copy link
Contributor

garyburd commented Nov 10, 2017

You can connect through a socks5 proxy by setting the Dialer.NetDial field to the Dial method of a SOCKS5 Dialer.

 netDialer, err := proxy.SOCKS5( .... )
 if err != nil {
    handle error
 }
 dialer := websocket.Dialer{NetDial: netDialer.Dial}
 c, r, err := dialer.Dial(url, nil)
 if err != nil {
    handle error
}

@vitreuz
Copy link

vitreuz commented Nov 10, 2017

We use the http.ProxyFromEnvironment function to setup the Dialer.Proxy field.

if proxy == nil {
    proxy = http.ProxyFromEnvironment
}

...

    dialer: websocket.Dialer{
        Proxy:            proxy,
        ...
    },

Would it be possible to support this out of the box since golang recently added support for SOCKS5 from the environment? They have a similar implementation for the transport package here.

@garyburd
Copy link
Contributor

@vitreuz I don't want to add a dependency outside the standard library, nor do I want to vendor the x/net package as was done here.

I am open to suggestions on how to modify the Dialer to enable easy use of golang.org/x/net/proxy by applications.

@garyburd
Copy link
Contributor

garyburd commented Nov 11, 2017

How about adding this field to Dialer?

// ProxyDialerFromURL returns a dialer given a Proxy URL specification and an underlying
// dialer for it to make network requests. The Dialer.Dial method defaults to using an HTTP
// proxy if ProxyDialerFromURL is nil or the function returns an unknown scheme error.
//
// The ProxyFromURL function in the package golang.org/x/net/proxy can be used as 
// a ProxyDialerFromURL function.
ProxyDialerFromURL func(u *url.URL, forward Dialer) (Dialer, error) 

@enocom
Copy link

enocom commented Nov 15, 2017

@garyburd Your solution looks great. It will solve the problem of needing to support SOCKS5 in our particular library NOAA. @melnikalex What do you think?

@melnikalex
Copy link
Author

@garyburd I like it. Thank you!

@garyburd
Copy link
Contributor

Another approach is to bundle the x/net/proxy package. This avoids adding yet another knob to Dialer and is a much better option than vendoring all of x/net.

@garyburd garyburd self-assigned this Nov 30, 2017
garyburd added a commit that referenced this issue Dec 1, 2017
- Bundle the golang.org/x/net/proxy package to x_net_proxy.go. The
package contains a SOCKS5 proxy. The package is bundled to avoid adding
a dependency from the weboscket package to golang.org/x/net.
- Restructure the existing HTTP proxy code so the code can be used as a
dialer with the proxy package.
- Modify Dialer.Dial to use proxy.FromURL.
- Improve tests (avoid modifying package-level data, use timeouts in
tests, use correct proxy URLs in tests).

Fixes #297.
@gorilla gorilla locked and limited conversation to collaborators Aug 29, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants