Skip to content

Commit 2453caf

Browse files
authored
fix: route websocket upgrades through new handler API (#4787)
1 parent 4658cdf commit 2453caf

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

lib/web/fetch/index.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2302,6 +2302,41 @@ async function httpNetworkFetch (
23022302
reject(error)
23032303
},
23042304

2305+
onRequestUpgrade (_controller, status, headers, socket) {
2306+
// We need to support 200 for websocket over h2 as per RFC-8441
2307+
// Absence of session means H1
2308+
if ((socket.session != null && status !== 200) || (socket.session == null && status !== 101)) {
2309+
return false
2310+
}
2311+
2312+
const headersList = new HeadersList()
2313+
2314+
for (const [name, value] of Object.entries(headers)) {
2315+
if (value == null) {
2316+
continue
2317+
}
2318+
2319+
const headerName = name.toLowerCase()
2320+
2321+
if (Array.isArray(value)) {
2322+
for (const entry of value) {
2323+
headersList.append(headerName, String(entry), true)
2324+
}
2325+
} else {
2326+
headersList.append(headerName, String(value), true)
2327+
}
2328+
}
2329+
2330+
resolve({
2331+
status,
2332+
statusText: STATUS_CODES[status],
2333+
headersList,
2334+
socket
2335+
})
2336+
2337+
return true
2338+
},
2339+
23052340
onUpgrade (status, rawHeaders, socket) {
23062341
// We need to support 200 for websocket over h2 as per RFC-8441
23072342
// Absence of session means H1

0 commit comments

Comments
 (0)