@@ -23,8 +23,8 @@ func (o acceptSubprotocols) acceptOption() {}
23
23
24
24
// AcceptSubprotocols list the subprotocols that Accept will negotiate with a client.
25
25
// The first protocol that a client supports will be negotiated.
26
- // Pass "" as a subprotocol if you would like to allow the default protocol along with
27
- // specific subprotocols .
26
+ // The empty protocol will always be negotiated as per RFC 6455. If you would like to
27
+ // reject it, close the connection is c.Subprotocol() == "" .
28
28
func AcceptSubprotocols (subprotocols ... string ) AcceptOption {
29
29
return acceptSubprotocols (subprotocols )
30
30
}
@@ -42,7 +42,7 @@ func (o acceptOrigins) acceptOption() {}
42
42
// See https://stackoverflow.com/a/37837709/4283659
43
43
// You can use a * for wildcards.
44
44
func AcceptOrigins (origins ... string ) AcceptOption {
45
- return AcceptOrigins (origins ... )
45
+ return acceptOrigins (origins )
46
46
}
47
47
48
48
// Accept accepts a WebSocket handshake from a client and upgrades the
@@ -135,7 +135,7 @@ func Accept(w http.ResponseWriter, r *http.Request, opts ...AcceptOption) (*Conn
135
135
}
136
136
137
137
func selectSubprotocol (w http.ResponseWriter , r * http.Request , subprotocols []string ) {
138
- clientSubprotocols := strings .Split (r .Header .Get ("Sec-WebSocket-Protocol" ), "\n " )
138
+ clientSubprotocols := strings .Split (r .Header .Get ("Sec-WebSocket-Protocol" ), ", " )
139
139
for _ , sp := range subprotocols {
140
140
for _ , cp := range clientSubprotocols {
141
141
if sp == strings .TrimSpace (cp ) {
@@ -168,9 +168,9 @@ func authenticateOrigin(r *http.Request, origins []string) error {
168
168
return xerrors .Errorf ("failed to parse Origin header %q: %w" , origin , err )
169
169
}
170
170
for _ , o := range origins {
171
- if u .Host == o {
171
+ if strings . EqualFold ( u .Host , o ) {
172
172
return nil
173
173
}
174
174
}
175
- return xerrors .New ("request origin is not authorized" )
175
+ return xerrors .Errorf ("request origin %q is not authorized" , r . Header . Get ( "Origin" ) )
176
176
}
0 commit comments