diff options
Diffstat (limited to 'ext')
-rw-r--r-- | ext/flash/01_http.js | 26 | ||||
-rw-r--r-- | ext/http/01_http.js | 14 |
2 files changed, 27 insertions, 13 deletions
diff --git a/ext/flash/01_http.js b/ext/flash/01_http.js index a9ae9d85a..962b22729 100644 --- a/ext/flash/01_http.js +++ b/ext/flash/01_http.js @@ -3,7 +3,9 @@ ((window) => { const { BlobPrototype } = window.__bootstrap.file; - const { fromFlashRequest, toInnerResponse } = window.__bootstrap.fetch; + const { TcpConn } = window.__bootstrap.net; + const { fromFlashRequest, toInnerResponse, _flash } = + window.__bootstrap.fetch; const core = window.Deno.core; const { ReadableStream, @@ -18,7 +20,6 @@ _readyState, _eventLoop, _protocol, - _server, _idleTimeoutDuration, _idleTimeoutTimeout, _serverHandleIdleTimeout, @@ -597,7 +598,28 @@ }); } + function upgradeHttpRaw(req) { + if (!req[_flash]) { + throw new TypeError( + "Non-flash requests can not be upgraded with `upgradeHttpRaw`. Use `upgradeHttp` instead.", + ); + } + + // NOTE(bartlomieju): + // Access these fields so they are cached on `req` object, otherwise + // they wouldn't be available after the connection gets upgraded. + req.url; + req.method; + req.headers; + + const { serverId, streamRid } = req[_flash]; + const connRid = core.ops.op_flash_upgrade_http(streamRid, serverId); + // TODO(@littledivy): return already read first packet too. + return [new TcpConn(connRid), new Uint8Array()]; + } + window.__bootstrap.flash = { serve, + upgradeHttpRaw, }; })(this); diff --git a/ext/http/01_http.js b/ext/http/01_http.js index 6df26d09f..63023a296 100644 --- a/ext/http/01_http.js +++ b/ext/http/01_http.js @@ -477,17 +477,9 @@ function upgradeHttp(req) { if (req[_flash]) { - // NOTE(bartlomieju): - // Access these fields so they are cached on `req` object, otherwise - // they wouldn't be available after the connection gets upgraded. - req.url; - req.method; - req.headers; - - const { serverId, streamRid } = req[_flash]; - const connRid = core.ops.op_flash_upgrade_http(streamRid, serverId); - // TODO(@littledivy): return already read first packet too. - return [new TcpConn(connRid), new Uint8Array()]; + throw new TypeError( + "Flash requests can not be upgraded with `upgradeHttp`. Use `upgradeHttpRaw` instead.", + ); } req[_deferred] = new Deferred(); |