From 074f53234a161b3ef02d3d28e3ff16053fa69a5a Mon Sep 17 00:00:00 2001 From: ylxdzsw Date: Wed, 16 Feb 2022 07:16:12 +0800 Subject: feat(ext/http): add support for unix domain sockets (#13628) --- runtime/ops/http.rs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'runtime/ops') diff --git a/runtime/ops/http.rs b/runtime/ops/http.rs index fddac9261..53a99bd47 100644 --- a/runtime/ops/http.rs +++ b/runtime/ops/http.rs @@ -8,6 +8,7 @@ use deno_core::OpState; use deno_core::ResourceId; use deno_http::http_create_conn_resource; use deno_net::io::TcpStreamResource; +use deno_net::io::UnixStreamResource; use deno_net::ops_tls::TlsStreamResource; pub fn init() -> Extension { @@ -45,5 +46,20 @@ fn op_http_start( return http_create_conn_resource(state, tls_stream, addr, "https"); } + #[cfg(unix)] + if let Ok(resource_rc) = state + .resource_table + .take::(tcp_stream_rid) + { + super::check_unstable(state, "Deno.serveHttp"); + + let resource = Rc::try_unwrap(resource_rc) + .expect("Only a single use of this resource should happen"); + let (read_half, write_half) = resource.into_inner(); + let unix_stream = read_half.reunite(write_half)?; + let addr = unix_stream.local_addr()?; + return http_create_conn_resource(state, unix_stream, addr, "http+unix"); + } + Err(bad_resource_id()) } -- cgit v1.2.3