summaryrefslogtreecommitdiff
path: root/ext/flash/01_http.js
diff options
context:
space:
mode:
authorLuca Casonato <hello@lcas.dev>2022-08-24 14:10:57 +0200
committerGitHub <noreply@github.com>2022-08-24 17:40:57 +0530
commitf3bde1d53b4710fb526286e27af29a55f5da18c7 (patch)
treee9ff07886e5cc7ac0535ece0c47fe2447b509e4d /ext/flash/01_http.js
parent452df99222911c772657c39491469bd97935f23a (diff)
feat(ext/flash): split upgradeHttp into two APIs (#15557)
This commit splits `Deno.upgradeHttp` into two different APIs, because the same API is currently overloaded with two different functions. Flash requests upgrade immediately, with no need to return a `Response` object. Instead you have to manually write the response to the socket. Hyper requests only upgrade once a `Response` object has been sent. These two behaviours are now split into `Deno.upgradeHttp` and `Deno.upgradeHttpRaw`. The latter is flash only. The former only supports hyper requests at the moment, but can be updated to support flash in the future. Additionally this removes `void | Promise<void>` as valid return types for the handler function. If one wants to use `Deno.upgradeHttpRaw`, they will have to type cast the handler signature - the signature is meant for the 99.99%, and should not be complicated for the 0.01% that use `Deno.upgradeHttpRaw()`.
Diffstat (limited to 'ext/flash/01_http.js')
-rw-r--r--ext/flash/01_http.js26
1 files changed, 24 insertions, 2 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);