summaryrefslogtreecommitdiff
path: root/runtime/ops/http.rs
diff options
context:
space:
mode:
authorylxdzsw <ylxdzsw@gmail.com>2022-02-16 07:16:12 +0800
committerGitHub <noreply@github.com>2022-02-16 00:16:12 +0100
commit074f53234a161b3ef02d3d28e3ff16053fa69a5a (patch)
treed4cfed3c7e97088581d2e2a96a41f807f247e7d0 /runtime/ops/http.rs
parent2dc5dba8baf148a525cbb7987cdad0ba6398c5e4 (diff)
feat(ext/http): add support for unix domain sockets (#13628)
Diffstat (limited to 'runtime/ops/http.rs')
-rw-r--r--runtime/ops/http.rs16
1 files changed, 16 insertions, 0 deletions
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::<UnixStreamResource>(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())
}