diff --git a/README.md b/README.md index 4ee0a30e80b0bdaa86450785e114d74d5ffff9c3..94a569dbf77142fb70aa788a7a20a58d44b7f8a7 100644 --- a/README.md +++ b/README.md @@ -16,10 +16,10 @@ go get nhooyr.io/websocket@v1.5.0 - Minimal and idiomatic API - Tiny codebase at 1700 lines -- First class context.Context support +- First class [context.Context](https://blog.golang.org/context) support - Thorough tests, fully passes the [autobahn-testsuite](https://github.com/crossbario/autobahn-testsuite) -- Zero dependencies outside of the stdlib for the core library -- JSON and ProtoBuf helpers in the wsjson and wspb subpackages +- [Zero dependencies](https://godoc.org/nhooyr.io/websocket?imports) +- JSON and ProtoBuf helpers in the [wsjson](https://godoc.org/nhooyr.io/websocket/wsjson) and [wspb](https://godoc.org/nhooyr.io/websocket/wspb) subpackages - Highly optimized by default - Concurrent writes out of the box @@ -172,4 +172,4 @@ This is a list of companies or projects that use this library. - [Coder](https://github.com/cdr) -If your company or project is using this library, please feel free to open a PR to amend the list. +If your company or project is using this library, please feel free to open an issue or PR to amend the list. diff --git a/accept.go b/accept.go index afad1be2ec4771e6405688af706b9019fee9701e..fc211d7eac3ad89145ab1c533e961135c6897cb9 100644 --- a/accept.go +++ b/accept.go @@ -10,7 +10,6 @@ import ( "net/url" "strings" - "golang.org/x/net/http/httpguts" "golang.org/x/xerrors" ) @@ -151,9 +150,29 @@ func accept(w http.ResponseWriter, r *http.Request, opts *AcceptOptions) (*Conn, return c, nil } -func headerValuesContainsToken(h http.Header, key, val string) bool { +func headerValuesContainsToken(h http.Header, key, token string) bool { key = textproto.CanonicalMIMEHeaderKey(key) - return httpguts.HeaderValuesContainsToken(h[key], val) + + for _, val2 := range h[key] { + if headerValueContainsToken(val2, token) { + return true + } + } + + return false +} + +func headerValueContainsToken(val2, token string) bool { + val2 = strings.TrimSpace(val2) + + for _, val2 := range strings.Split(val2, ",") { + val2 = strings.TrimSpace(val2) + if strings.EqualFold(val2, token) { + return true + } + } + + return false } func selectSubprotocol(r *http.Request, subprotocols []string) string { diff --git a/go.mod b/go.mod index 70fe1d4c111e94136ef01f194866cf2e86228d77..9e8e33b7fdc2406746726054779e2203355565b9 100644 --- a/go.mod +++ b/go.mod @@ -18,9 +18,7 @@ require ( go.uber.org/atomic v1.4.0 // indirect go.uber.org/multierr v1.1.0 golang.org/x/lint v0.0.0-20190409202823-959b441ac422 - golang.org/x/net v0.0.0-20190827160401-ba9fcec4b297 golang.org/x/sys v0.0.0-20190830142957-1e83adbbebd0 // indirect - golang.org/x/text v0.3.2 // indirect golang.org/x/time v0.0.0-20190308202827-9d24e82272b4 golang.org/x/tools v0.0.0-20190830223141-573d9926052a golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7 diff --git a/go.sum b/go.sum index 906f9c38cb955e94ef5e56445b685b9959199d7f..18b3dd70751a82d53d34685dde090197e2663d98 100644 --- a/go.sum +++ b/go.sum @@ -78,8 +78,6 @@ golang.org/x/net v0.0.0-20181102091132-c10e9556a7bc/go.mod h1:mL1N/T3taQHkDXs73r golang.org/x/net v0.0.0-20190311183353-d8887717615a h1:oWX7TPOiFAMXLq8o0ikBYfCJVlRHBcsciT5bXOrH628= golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= -golang.org/x/net v0.0.0-20190827160401-ba9fcec4b297 h1:k7pJ2yAPLPgbskkFdhRCsA77k2fySZ1zf2zCjvQCiIM= -golang.org/x/net v0.0.0-20190827160401-ba9fcec4b297/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20190423024810-112230192c58 h1:8gQV6CLnAEikrhgkHFbMAEhagSSnXWGV915qUMm9mrU= golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= @@ -93,11 +91,8 @@ golang.org/x/sys v0.0.0-20190830142957-1e83adbbebd0 h1:7z820YPX9pxWR59qM7BE5+fgl golang.org/x/sys v0.0.0-20190830142957-1e83adbbebd0/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= -golang.org/x/text v0.3.2 h1:tW2bmiBqwgJj/UpqtC8EpXEZVYOwU0yG4iWbprSVAcs= -golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= golang.org/x/time v0.0.0-20190308202827-9d24e82272b4 h1:SvFZT6jyqRaOeXpc5h/JSfZenJ2O330aBsf7JfSUXmQ= golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= -golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= golang.org/x/tools v0.0.0-20190830223141-573d9926052a h1:XAHT1kdPpnU8Hk+FPi42KZFhtNFEk4vBg1U4OmIeHTU= golang.org/x/tools v0.0.0-20190830223141-573d9926052a/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=