@@ -114,14 +114,26 @@ func negotiateProtocol(clientProtocols, serverProtocols []string) string {
114
114
return ""
115
115
}
116
116
117
+ func commaSeparatedHeaderValues (header []string ) []string {
118
+ var parsedClientProtocols []string
119
+ for i := range header {
120
+ for _ , clientProtocol := range strings .Split (header [i ], "," ) {
121
+ if proto := strings .Trim (clientProtocol , " " ); len (proto ) > 0 {
122
+ parsedClientProtocols = append (parsedClientProtocols , proto )
123
+ }
124
+ }
125
+ }
126
+ return parsedClientProtocols
127
+ }
128
+
117
129
// Handshake performs a subprotocol negotiation. If the client did request a
118
130
// subprotocol, Handshake will select the first common value found in
119
131
// serverProtocols. If a match is found, Handshake adds a response header
120
132
// indicating the chosen subprotocol. If no match is found, HTTP forbidden is
121
133
// returned, along with a response header containing the list of protocols the
122
134
// server can accept.
123
135
func Handshake (req * http.Request , w http.ResponseWriter , serverProtocols []string ) (string , error ) {
124
- clientProtocols := req .Header [http .CanonicalHeaderKey (HeaderProtocolVersion )]
136
+ clientProtocols := commaSeparatedHeaderValues ( req .Header [http .CanonicalHeaderKey (HeaderProtocolVersion )])
125
137
if len (clientProtocols ) == 0 {
126
138
return "" , fmt .Errorf ("unable to upgrade: %s is required" , HeaderProtocolVersion )
127
139
}
0 commit comments