@@ -102,12 +102,11 @@ class WSHandler {
102102 socket . unshift ( this . head )
103103 }
104104
105- headers = copyHeaders ( headers , null )
106-
107105 setupSocket ( socket )
108106
109107 let head = 'HTTP/1.1 101 Switching Protocols\r\nconnection: upgrade\r\nupgrade: websocket'
110108
109+ headers = copyHeaders ( headers , null )
111110 for ( let n = 0 ; n < headers . length ; n += 2 ) {
112111 const key = headers [ n + 0 ]
113112 const val = headers [ n + 1 ]
@@ -148,20 +147,20 @@ function getRequestHeaders (ctx) {
148147 const key = headers [ n + 0 ]
149148 const val = headers [ n + 1 ]
150149
151- if ( ! via && key . length === 3 && / ^ v i a $ / i . test ( key ) ) {
150+ if ( ! via && key . length === 3 && key . toLowerCase ( ) === 'via' ) {
152151 via = val
153- } else if ( ! host && key . length === 4 && / ^ h o s t $ / i . test ( key ) ) {
152+ } else if ( ! host && key . length === 4 && key . toLowerCase ( ) === 'host' ) {
154153 host = val
155- } else if ( ! forwarded && key . length === 9 && / ^ f o r w a r d e d $ / . test ( key ) ) {
154+ } else if ( ! forwarded && key . length === 9 && key . toLowerCase ( ) === 'forwarded' ) {
156155 forwarded = val
157- } else if ( ! authority && key . length === 10 && / ^ : a u t h o r i t y $ / i. test ( key ) ) {
158- authority = val
159- } else if ( ! connection && key . length === 10 && / ^ c o n n e c t i o n $ / i. test ( key ) ) {
156+ } else if ( ! connection && key . length === 10 && key . toLowerCase ( ) === 'connection' ) {
160157 connection = val
158+ } else if ( ! authority && key . length === 10 && key === ':authority' ) {
159+ authority = val
161160 }
162161 }
163162
164- const result = copyHeaders ( headers )
163+ const result = copyHeaders ( headers , connection )
165164
166165 // TODO(fix): <host> [ ":" <port> ] vs <pseudonym>
167166 // See, https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Via.
@@ -189,18 +188,18 @@ function getRequestHeaders (ctx) {
189188 return result
190189}
191190
192- // This expression matched hop-by-hop headers.
191+ // This expression matches hop-by-hop headers.
193192// These headers are meaningful only for a single transport-level connection,
194193// and must not be retransmitted by proxies or cached.
195- // Note that only hop-by-hop headers may be set using the Connection general header.
196194const HOP_EXPR = / ^ ( t e | h o s t | u p g r a d e | t r a i l e r s | c o n n e c t i o n | k e e p - a l i v e | h t t p 2 - s e t t i n g s | t r a n s f e r - e n c o d i n g | p r o x y - c o n n e c t i o n | p r o x y - a u t h e n t i c a t e | p r o x y - a u t h o r i z a t i o n ) $ / i
197195
198196// Removes hop-by-hop and pseudo headers.
197+ // Only hop-by-hop headers may be set using the Connection general header.
199198function copyHeaders ( headers , connection ) {
200199 if ( ! connection ) {
201200 for ( let n = 0 ; n < headers . length ; n += 2 ) {
202201 const key = headers [ n + 0 ]
203- if ( key . length === 10 && / ^ c o n n e c t i o n $ / i . test ( key ) ) {
202+ if ( key . length === 10 && key . toLowerCase ( ) === 'connection' ) {
204203 connection = headers [ n + 1 ]
205204 break
206205 }
0 commit comments