mirror of
https://github.com/fafhrd91/actix-net
synced 2024-11-27 16:52:58 +01:00
actix-tls: allow getting uri from Connect (#415)
Co-authored-by: Rob Ede <robjtede@icloud.com>
This commit is contained in:
parent
443a328fb4
commit
0b0cbd5388
@ -1,6 +1,9 @@
|
|||||||
# Changes
|
# Changes
|
||||||
|
|
||||||
## Unreleased - 2021-xx-xx
|
## 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
|
## 3.0.0-beta.7 - 2021-10-20
|
||||||
|
@ -63,16 +63,16 @@ impl From<Option<SocketAddr>> for ConnectAddrs {
|
|||||||
|
|
||||||
/// Connection info.
|
/// Connection info.
|
||||||
#[derive(Debug, PartialEq, Eq, Hash)]
|
#[derive(Debug, PartialEq, Eq, Hash)]
|
||||||
pub struct Connect<T> {
|
pub struct Connect<R> {
|
||||||
pub(crate) req: T,
|
pub(crate) req: R,
|
||||||
pub(crate) port: u16,
|
pub(crate) port: u16,
|
||||||
pub(crate) addr: ConnectAddrs,
|
pub(crate) addr: ConnectAddrs,
|
||||||
pub(crate) local_addr: Option<IpAddr>,
|
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
|
/// 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());
|
let (_, port) = parse_host(req.hostname());
|
||||||
|
|
||||||
Connect {
|
Connect {
|
||||||
@ -85,7 +85,7 @@ impl<T: Address> Connect<T> {
|
|||||||
|
|
||||||
/// Create new `Connect` instance from host and address. Connector skips name resolution stage
|
/// Create new `Connect` instance from host and address. Connector skips name resolution stage
|
||||||
/// for such connect messages.
|
/// 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 {
|
Connect {
|
||||||
req,
|
req,
|
||||||
port: 0,
|
port: 0,
|
||||||
@ -155,15 +155,20 @@ impl<T: Address> Connect<T> {
|
|||||||
ConnectAddrs::Multi(addrs) => ConnectAddrsIter::MultiOwned(addrs.into_iter()),
|
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> {
|
impl<R: Address> From<R> for Connect<R> {
|
||||||
fn from(addr: T) -> Self {
|
fn from(addr: R) -> Self {
|
||||||
Connect::new(addr)
|
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 {
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
write!(f, "{}:{}", self.hostname(), self.port())
|
write!(f, "{}:{}", self.hostname(), self.port())
|
||||||
}
|
}
|
||||||
@ -347,4 +352,10 @@ mod tests {
|
|||||||
IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1))
|
IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1))
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn request_ref() {
|
||||||
|
let conn = Connect::new("hello");
|
||||||
|
assert_eq!(conn.request(), &"hello")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user