diff --git a/actix-tls/CHANGES.md b/actix-tls/CHANGES.md index d3d1f761..ad991d42 100644 --- a/actix-tls/CHANGES.md +++ b/actix-tls/CHANGES.md @@ -1,6 +1,9 @@ # Changes ## Unreleased - 2021-xx-xx +* Add `Connect::request` for getting a reference to the connection request. [#415] + +[#415]: https://github.com/actix/actix-net/pull/415 ## 3.0.0-beta.7 - 2021-10-20 diff --git a/actix-tls/src/connect/connect.rs b/actix-tls/src/connect/connect.rs index 730486cf..65d9e05e 100755 --- a/actix-tls/src/connect/connect.rs +++ b/actix-tls/src/connect/connect.rs @@ -63,16 +63,16 @@ impl From> for ConnectAddrs { /// Connection info. #[derive(Debug, PartialEq, Eq, Hash)] -pub struct Connect { - pub(crate) req: T, +pub struct Connect { + pub(crate) req: R, pub(crate) port: u16, pub(crate) addr: ConnectAddrs, pub(crate) local_addr: Option, } -impl Connect { +impl Connect { /// Create `Connect` instance by splitting the string by ':' and convert the second part to u16 - pub fn new(req: T) -> Connect { + pub fn new(req: R) -> Connect { let (_, port) = parse_host(req.hostname()); Connect { @@ -85,7 +85,7 @@ impl Connect { /// Create new `Connect` instance from host and address. Connector skips name resolution stage /// for such connect messages. - pub fn with_addr(req: T, addr: SocketAddr) -> Connect { + pub fn with_addr(req: R, addr: SocketAddr) -> Connect { Connect { req, port: 0, @@ -155,15 +155,20 @@ impl Connect { ConnectAddrs::Multi(addrs) => ConnectAddrsIter::MultiOwned(addrs.into_iter()), } } + + /// Returns a reference to the connection request. + pub fn request(&self) -> &R { + &self.req + } } -impl From for Connect { - fn from(addr: T) -> Self { +impl From for Connect { + fn from(addr: R) -> Self { Connect::new(addr) } } -impl fmt::Display for Connect { +impl fmt::Display for Connect { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "{}:{}", self.hostname(), self.port()) } @@ -347,4 +352,10 @@ mod tests { IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)) ) } + + #[test] + fn request_ref() { + let conn = Connect::new("hello"); + assert_eq!(conn.request(), &"hello") + } }