mirror of
https://github.com/fafhrd91/actix-net
synced 2024-11-23 21:51:06 +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
|
||||
|
||||
## 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
|
||||
|
@ -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 {
|
||||
@ -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,
|
||||
@ -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())
|
||||
}
|
||||
@ -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")
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user