1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-12-24 16:19:12 -05:00

fix(runtime): include HTTP op in WebWorker (#10207)

This commit is contained in:
Satya Rohith 2021-04-20 19:56:31 +05:30 committed by GitHub
parent 9e6cd91014
commit 15ffdd2624
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 35 additions and 0 deletions

View file

@ -0,0 +1,10 @@
// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license.
const listener = Deno.listen({ hostname: "127.0.0.1", port: 4500 });
for await (const conn of listener) {
(async () => {
const requests = Deno.serveHttp(conn);
for await (const { respondWith } of requests) {
respondWith(new Response("Hello world"));
}
})();
}

View file

@ -697,3 +697,27 @@ Deno.test({
worker.terminate(); worker.terminate();
}, },
}); });
Deno.test({
name: "Worker with native HTTP",
fn: async function () {
const worker = new Worker(
new URL(
"./http_worker.js",
import.meta.url,
).href,
{
type: "module",
deno: {
namespace: true,
permissions: "inherit",
},
},
);
assert(worker);
const response = await fetch("http://localhost:4500");
assert(await response.arrayBuffer());
worker.terminate();
},
});

View file

@ -261,6 +261,7 @@ impl WebWorker {
ops::fs::init(js_runtime); ops::fs::init(js_runtime);
ops::net::init(js_runtime); ops::net::init(js_runtime);
ops::os::init(js_runtime); ops::os::init(js_runtime);
ops::http::init(js_runtime);
ops::permissions::init(js_runtime); ops::permissions::init(js_runtime);
ops::plugin::init(js_runtime); ops::plugin::init(js_runtime);
ops::process::init(js_runtime); ops::process::init(js_runtime);