Skip to content

Commit

Permalink
actix-tls: allow getting uri from Connect (#415)
Browse files Browse the repository at this point in the history
Co-authored-by: Rob Ede <robjtede@icloud.com>
  • Loading branch information
polachok and robjtede authored Nov 15, 2021
1 parent 443a328 commit 0b0cbd5
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 8 deletions.
3 changes: 3 additions & 0 deletions actix-tls/CHANGES.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
27 changes: 19 additions & 8 deletions actix-tls/src/connect/connect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,16 +63,16 @@ impl From<Option<SocketAddr>> for ConnectAddrs {

/// Connection info.
#[derive(Debug, PartialEq, Eq, Hash)]
pub struct Connect<T> {
pub(crate) req: T,
pub struct Connect<R> {
pub(crate) req: R,
pub(crate) port: u16,
pub(crate) addr: ConnectAddrs,
pub(crate) local_addr: Option<IpAddr>,
}

impl<T: Address> Connect<T> {
impl<R: Address> Connect<R> {
/// Create `Connect` instance by splitting the string by ':' and convert the second part to u16
pub fn new(req: T) -> Connect<T> {
pub fn new(req: R) -> Connect<R> {
let (_, port) = parse_host(req.hostname());

Connect {
Expand All @@ -85,7 +85,7 @@ impl<T: Address> Connect<T> {

/// 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<T> {
pub fn with_addr(req: R, addr: SocketAddr) -> Connect<R> {
Connect {
req,
port: 0,
Expand Down Expand Up @@ -155,15 +155,20 @@ impl<T: Address> Connect<T> {
ConnectAddrs::Multi(addrs) => ConnectAddrsIter::MultiOwned(addrs.into_iter()),
}
}

/// Returns a reference to the connection request.
pub fn request(&self) -> &R {
&self.req
}
}

impl<T: Address> From<T> for Connect<T> {
fn from(addr: T) -> Self {
impl<R: Address> From<R> for Connect<R> {
fn from(addr: R) -> Self {
Connect::new(addr)
}
}

impl<T: Address> fmt::Display for Connect<T> {
impl<R: Address> fmt::Display for Connect<R> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{}:{}", self.hostname(), self.port())
}
Expand Down Expand Up @@ -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")
}
}

0 comments on commit 0b0cbd5

Please sign in to comment.