diff options
author | Divy Srivastava <dj.srivastava23@gmail.com> | 2022-08-18 17:35:02 +0530 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-08-18 17:35:02 +0530 |
commit | cd21cff29942f24ba7d38287186cce64d0e84e56 (patch) | |
tree | e663eff884526ee762ae9141a3cf5a0f6967a84e /cli/bench/http/deno_http_flash_ops.js | |
parent | 0b0843e4a54d7c1ddf293ac1ccee2479b69a5ba9 (diff) |
feat(ext/flash): An optimized http/1.1 server (#15405)
Co-authored-by: Bartek IwaĆczuk <biwanczuk@gmail.com>
Co-authored-by: Ben Noordhuis <info@bnoordhuis.nl>
Co-authored-by: crowlkats <crowlkats@toaxl.com>
Co-authored-by: Ryan Dahl <ry@tinyclouds.org>
Diffstat (limited to 'cli/bench/http/deno_http_flash_ops.js')
-rw-r--r-- | cli/bench/http/deno_http_flash_ops.js | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/cli/bench/http/deno_http_flash_ops.js b/cli/bench/http/deno_http_flash_ops.js new file mode 100644 index 000000000..1b833e7f7 --- /dev/null +++ b/cli/bench/http/deno_http_flash_ops.js @@ -0,0 +1,37 @@ +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. + +// deno-lint-ignore-file + +const { + core: { + opAsync, + ops: { op_flash_make_request, op_flash_serve }, + encode, + }, +} = Deno; +const addr = Deno.args[0] || "127.0.0.1:4500"; +const [hostname, port] = addr.split(":"); +const serverId = op_flash_serve({ hostname, port }); +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", +); +while (true) { + let token = nextRequest(); + if (token === 0) token = await opAsync("op_flash_next_async", serverId); + for (let i = 0; i < token; i++) { + respond( + i, + response, + ); + } +} |