2023-01-02 16:00:42 -05:00
|
|
|
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
|
2022-08-18 08:05:02 -04:00
|
|
|
|
|
|
|
// deno-lint-ignore-file
|
|
|
|
|
|
|
|
const {
|
2023-01-24 12:54:10 -05:00
|
|
|
opAsync,
|
|
|
|
ops: { op_flash_make_request, op_flash_serve },
|
|
|
|
encode,
|
|
|
|
} = Deno[Deno.internal].core;
|
2022-08-18 08:05:02 -04:00
|
|
|
const addr = Deno.args[0] || "127.0.0.1:4500";
|
|
|
|
const [hostname, port] = addr.split(":");
|
2022-09-28 13:46:29 -04:00
|
|
|
const serverId = op_flash_serve({ hostname, port, reuseport: true });
|
2022-08-18 08:05:02 -04:00
|
|
|
const serverPromise = opAsync("op_flash_drive_server", serverId);
|
|
|
|
|
|
|
|
const fastOps = op_flash_make_request();
|
|
|
|
function nextRequest() {
|
|
|
|
return fastOps.nextRequest();
|
|
|
|
}
|
|
|
|
function respond(token, response) {
|
|
|
|
return fastOps.respond(token, response, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
const response = encode(
|
|
|
|
"HTTP/1.1 200 OK\r\nContent-Length: 11\r\n\r\nHello World",
|
|
|
|
);
|
2022-08-19 00:44:56 -04:00
|
|
|
let offset = 0;
|
2022-08-18 08:05:02 -04:00
|
|
|
while (true) {
|
|
|
|
let token = nextRequest();
|
|
|
|
if (token === 0) token = await opAsync("op_flash_next_async", serverId);
|
2022-08-19 00:44:56 -04:00
|
|
|
for (let i = offset; i < offset + token; i++) {
|
2022-08-18 08:05:02 -04:00
|
|
|
respond(
|
|
|
|
i,
|
|
|
|
response,
|
|
|
|
);
|
|
|
|
}
|
2022-08-19 00:44:56 -04:00
|
|
|
offset += token;
|
2022-08-18 08:05:02 -04:00
|
|
|
}
|