Skip to content

Commit 7419561

Browse files
committed
fixup
1 parent fddfabc commit 7419561

1 file changed

Lines changed: 11 additions & 12 deletions

File tree

examples/proxy/proxy.js

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -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 && /^via$/i.test(key)) {
150+
if (!via && key.length === 3 && key.toLowerCase() === 'via') {
152151
via = val
153-
} else if (!host && key.length === 4 && /^host$/i.test(key)) {
152+
} else if (!host && key.length === 4 && key.toLowerCase() === 'host') {
154153
host = val
155-
} else if (!forwarded && key.length === 9 && /^forwarded$/.test(key)) {
154+
} else if (!forwarded && key.length === 9 && key.toLowerCase() === 'forwarded') {
156155
forwarded = val
157-
} else if (!authority && key.length === 10 && /^:authority$/i.test(key)) {
158-
authority = val
159-
} else if (!connection && key.length === 10 && /^connection$/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.
196194
const HOP_EXPR = /^(te|host|upgrade|trailers|connection|keep-alive|http2-settings|transfer-encoding|proxy-connection|proxy-authenticate|proxy-authorization)$/i
197195

198196
// Removes hop-by-hop and pseudo headers.
197+
// Only hop-by-hop headers may be set using the Connection general header.
199198
function 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 && /^connection$/i.test(key)) {
202+
if (key.length === 10 && key.toLowerCase() === 'connection') {
204203
connection = headers[n + 1]
205204
break
206205
}

0 commit comments

Comments
 (0)