mirror of https://github.com/gorilla/websocket.git
Merge branch 'master' into fix-issue-480
This commit is contained in:
commit
8b7305f5f5
|
@ -348,8 +348,8 @@ func (d *Dialer) DialContext(ctx context.Context, urlStr string, requestHeader h
|
|||
}
|
||||
|
||||
if resp.StatusCode != 101 ||
|
||||
!strings.EqualFold(resp.Header.Get("Upgrade"), "websocket") ||
|
||||
!strings.EqualFold(resp.Header.Get("Connection"), "upgrade") ||
|
||||
!tokenListContainsValue(resp.Header, "Upgrade", "websocket") ||
|
||||
!tokenListContainsValue(resp.Header, "Connection", "upgrade") ||
|
||||
resp.Header.Get("Sec-Websocket-Accept") != computeAcceptKey(challengeKey) {
|
||||
// Before closing the network connection on return from this
|
||||
// function, slurp up some of the response to aid application
|
||||
|
|
|
@ -481,6 +481,23 @@ func TestBadMethod(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestDialExtraTokensInRespHeaders(t *testing.T) {
|
||||
s := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
challengeKey := r.Header.Get("Sec-Websocket-Key")
|
||||
w.Header().Set("Upgrade", "foo, websocket")
|
||||
w.Header().Set("Connection", "upgrade, keep-alive")
|
||||
w.Header().Set("Sec-Websocket-Accept", computeAcceptKey(challengeKey))
|
||||
w.WriteHeader(101)
|
||||
}))
|
||||
defer s.Close()
|
||||
|
||||
ws, _, err := cstDialer.Dial(makeWsProto(s.URL), nil)
|
||||
if err != nil {
|
||||
t.Fatalf("Dial: %v", err)
|
||||
}
|
||||
defer ws.Close()
|
||||
}
|
||||
|
||||
func TestHandshake(t *testing.T) {
|
||||
s := newServer(t)
|
||||
defer s.Close()
|
||||
|
|
|
@ -123,7 +123,9 @@ func (u *Upgrader) selectSubprotocol(r *http.Request) string {
|
|||
// Upgrade upgrades the HTTP server connection to the WebSocket protocol.
|
||||
//
|
||||
// The responseHeader is included in the response to the client's upgrade
|
||||
// request. Use the responseHeader to specify cookies (Set-Cookie).
|
||||
|
||||
// request. Use the responseHeader to specify cookies (Set-Cookie). To specify
|
||||
// subprotocols supported by the server, set Upgrader.Subprotocols directly.
|
||||
//
|
||||
// If the upgrade fails, then Upgrade replies to the client with an HTTP error
|
||||
// response.
|
||||
|
|
Loading…
Reference in New Issue