Skip to content

Commit

Permalink
Add Proxy to WebsocketOptions
Browse files Browse the repository at this point in the history
Signed-off-by: Michal Sadowski <misad90@gmail.com>
  • Loading branch information
fulder committed Jun 18, 2020
1 parent ca94c53 commit ad86f96
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions websocket.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"io"
"net"
"net/http"
"net/url"
"sync"
"time"

Expand All @@ -15,8 +16,11 @@ import (
type WebsocketOptions struct {
ReadBufferSize int
WriteBufferSize int
Proxy ProxyFunction
}

type ProxyFunction func(req *http.Request) (*url.URL, error)

// NewWebsocket returns a new websocket and returns a net.Conn compatible interface using the gorilla/websocket package
func NewWebsocket(host string, tlsc *tls.Config, timeout time.Duration, requestHeader http.Header, options *WebsocketOptions) (net.Conn, error) {
if timeout == 0 {
Expand All @@ -27,9 +31,11 @@ func NewWebsocket(host string, tlsc *tls.Config, timeout time.Duration, requestH
// Apply default options
options = &WebsocketOptions{}
}

if options.Proxy == nil {
options.Proxy = http.ProxyFromEnvironment
}
dialer := &websocket.Dialer{
Proxy: http.ProxyFromEnvironment,
Proxy: options.Proxy,
HandshakeTimeout: timeout,
EnableCompression: false,
TLSClientConfig: tlsc,
Expand Down

0 comments on commit ad86f96

Please sign in to comment.