diff options
author | Matt Mastracci <matthew@mastracci.com> | 2023-04-02 15:27:12 -0600 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-04-02 23:27:12 +0200 |
commit | 513dadadcff3e54a59c7d943f33acd90ff12ad89 (patch) | |
tree | 512ed6eaf6a99f8d6766d7e545abd8bf3f18dada /ext/http/01_http.js | |
parent | d939a5e96c5ad1068a38186d01dc2ff0195478e5 (diff) |
feat(ext/http): add an op to perform raw HTTP upgrade (#18511)
This commit adds new "op_http_upgrade_early", that allows to hijack
existing "Deno.HttpConn" acquired from "Deno.serveHttp" API
and performing a Websocket upgrade on this connection.
This is not a public API and is meant to be used internally in the
"ext/node" polyfills for "http" module.
---------
Co-authored-by: Bartek IwaĆczuk <biwanczuk@gmail.com>
Diffstat (limited to 'ext/http/01_http.js')
-rw-r--r-- | ext/http/01_http.js | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/ext/http/01_http.js b/ext/http/01_http.js index 5b78bb2f2..7224df3c5 100644 --- a/ext/http/01_http.js +++ b/ext/http/01_http.js @@ -17,6 +17,7 @@ import { _flash, fromInnerRequest, newInnerRequest, + toInnerRequest, } from "ext:deno_fetch/23_request.js"; import { AbortController } from "ext:deno_web/03_abort_signal.js"; import { @@ -61,6 +62,7 @@ const { } = primordials; const connErrorSymbol = Symbol("connError"); +const streamRid = Symbol("streamRid"); const _deferred = Symbol("upgradeHttpDeferred"); class HttpConn { @@ -135,6 +137,7 @@ class HttpConn { body !== null ? new InnerBody(body) : null, false, ); + innerRequest[streamRid] = streamRid; const abortController = new AbortController(); const request = fromInnerRequest( innerRequest, @@ -471,6 +474,12 @@ function upgradeHttp(req) { return req[_deferred].promise; } +async function upgradeHttpRaw(req, tcpConn) { + const inner = toInnerRequest(req); + const res = await core.opAsync("op_http_upgrade_early", inner[streamRid]); + return new TcpConn(res, tcpConn.remoteAddr, tcpConn.localAddr); +} + const spaceCharCode = StringPrototypeCharCodeAt(" ", 0); const tabCharCode = StringPrototypeCharCodeAt("\t", 0); const commaCharCode = StringPrototypeCharCodeAt(",", 0); @@ -545,4 +554,4 @@ function buildCaseInsensitiveCommaValueFinder(checkText) { internals.buildCaseInsensitiveCommaValueFinder = buildCaseInsensitiveCommaValueFinder; -export { _ws, HttpConn, upgradeHttp, upgradeWebSocket }; +export { _ws, HttpConn, upgradeHttp, upgradeHttpRaw, upgradeWebSocket }; |