diff options
author | Matt Mastracci <matthew@mastracci.com> | 2023-04-22 11:48:21 -0600 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-04-22 11:48:21 -0600 |
commit | bdffcb409fd1e257db280ab73e07cc319711256c (patch) | |
tree | 9aca1c1e73f0249bba8b66781b79c358a7a00798 /ext/net/ops_tls.rs | |
parent | d137501a639cb315772866f6775fcd9f43e28f5b (diff) |
feat(ext/http): Rework Deno.serve using hyper 1.0-rc3 (#18619)
This is a rewrite of the `Deno.serve` API to live on top of hyper
1.0-rc3. The code should be more maintainable long-term, and avoids some
of the slower mpsc patterns that made the older code less efficient than
it could have been.
Missing features:
- `upgradeHttp` and `upgradeHttpRaw` (`upgradeWebSocket` is available,
however).
- Automatic compression is unavailable on responses.
Diffstat (limited to 'ext/net/ops_tls.rs')
-rw-r--r-- | ext/net/ops_tls.rs | 29 |
1 files changed, 27 insertions, 2 deletions
diff --git a/ext/net/ops_tls.rs b/ext/net/ops_tls.rs index c0cfb8674..8a7757066 100644 --- a/ext/net/ops_tls.rs +++ b/ext/net/ops_tls.rs @@ -61,6 +61,7 @@ use std::fs::File; use std::io; use std::io::BufReader; use std::io::ErrorKind; +use std::net::SocketAddr; use std::path::Path; use std::pin::Pin; use std::rc::Rc; @@ -115,6 +116,13 @@ impl TlsStream { Self::new(tcp, Connection::Client(tls)) } + pub fn new_client_side_from( + tcp: TcpStream, + connection: ClientConnection, + ) -> Self { + Self::new(tcp, Connection::Client(connection)) + } + pub fn new_server_side( tcp: TcpStream, tls_config: Arc<ServerConfig>, @@ -123,6 +131,13 @@ impl TlsStream { Self::new(tcp, Connection::Server(tls)) } + pub fn new_server_side_from( + tcp: TcpStream, + connection: ServerConnection, + ) -> Self { + Self::new(tcp, Connection::Server(connection)) + } + pub fn into_split(self) -> (ReadHalf, WriteHalf) { let shared = Shared::new(self); let rd = ReadHalf { @@ -132,6 +147,16 @@ impl TlsStream { (rd, wr) } + /// Convenience method to match [`TcpStream`]. + pub fn peer_addr(&self) -> Result<SocketAddr, io::Error> { + self.0.as_ref().unwrap().tcp.peer_addr() + } + + /// Convenience method to match [`TcpStream`]. + pub fn local_addr(&self) -> Result<SocketAddr, io::Error> { + self.0.as_ref().unwrap().tcp.local_addr() + } + /// Tokio-rustls compatibility: returns a reference to the underlying TCP /// stream, and a reference to the Rustls `Connection` object. pub fn get_ref(&self) -> (&TcpStream, &Connection) { @@ -954,8 +979,8 @@ fn load_private_keys_from_file( } pub struct TlsListenerResource { - tcp_listener: AsyncRefCell<TcpListener>, - tls_config: Arc<ServerConfig>, + pub(crate) tcp_listener: AsyncRefCell<TcpListener>, + pub(crate) tls_config: Arc<ServerConfig>, cancel_handle: CancelHandle, } |