From 70af8128767f2fc5a9c59107d3b5ddc00531db55 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartek=20Iwa=C5=84czuk?= Date: Fri, 9 Apr 2021 00:34:15 +0200 Subject: feat: native HTTP bindings (#9935) Co-authered-by: Luca Casonato Co-authered-by: Ben Noordhuis Co-authered-by: Ryan Dahl --- cli/bench/deno_http_native.js | 17 +++++++++++++++++ cli/bench/http.rs | 20 ++++++++++++++++++++ 2 files changed, 37 insertions(+) create mode 100644 cli/bench/deno_http_native.js (limited to 'cli/bench') diff --git a/cli/bench/deno_http_native.js b/cli/bench/deno_http_native.js new file mode 100644 index 000000000..fa779be21 --- /dev/null +++ b/cli/bench/deno_http_native.js @@ -0,0 +1,17 @@ +// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. + +const addr = Deno.args[0] || "127.0.0.1:4500"; +const [hostname, port] = addr.split(":"); +const listener = Deno.listen({ hostname, port: Number(port) }); +console.log("Server listening on", addr); + +const body = Deno.core.encode("Hello World"); + +for await (const conn of listener) { + (async () => { + const requests = Deno.startHttp(conn); + for await (const { respondWith } of requests) { + respondWith(new Response(body)); + } + })(); +} diff --git a/cli/bench/http.rs b/cli/bench/http.rs index 952f3f19b..690e26cf4 100644 --- a/cli/bench/http.rs +++ b/cli/bench/http.rs @@ -33,6 +33,7 @@ pub(crate) fn benchmark( res.insert("deno_tcp".to_string(), deno_tcp(deno_exe)?); // res.insert("deno_udp".to_string(), deno_udp(deno_exe)?); res.insert("deno_http".to_string(), deno_http(deno_exe)?); + res.insert("deno_http_native".to_string(), deno_http_native(deno_exe)?); // TODO(ry) deno_proxy disabled to make fetch() standards compliant. // res.insert("deno_proxy".to_string(), deno_http_proxy(deno_exe) hyper_hello_exe)) res.insert( @@ -200,6 +201,25 @@ fn deno_http(deno_exe: &str) -> Result { ) } +fn deno_http_native(deno_exe: &str) -> Result { + let port = get_port(); + println!("http_benchmark testing DENO using native bindings."); + run( + &[ + deno_exe, + "run", + "--allow-net", + "--reload", + "--unstable", + "cli/bench/deno_http_native.js", + &server_addr(port), + ], + port, + None, + None, + ) +} + #[allow(dead_code)] fn deno_http_proxy( deno_exe: &str, -- cgit v1.2.3