From cd70959360102546754b32aa18537832e6b00de9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Devrim=20=C5=9Eahin?= Date: Fri, 21 Apr 2023 12:37:16 +0300 Subject: [PATCH] remove the `Option` from local_addr, replace `unwrap()` --- src/http_interop.rs | 2 +- src/response.rs | 9 ++++++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/http_interop.rs b/src/http_interop.rs index d3e3cb33..0c0e1618 100644 --- a/src/http_interop.rs +++ b/src/http_interop.rs @@ -48,7 +48,7 @@ impl + Send + Sync + 'static> From> for Respons .collect::>(), reader: Box::new(Cursor::new(value.into_body())), remote_addr: SocketAddr::new(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)), 80), - local_addr: None, + local_addr: SocketAddr::new(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)), 0), history: vec![], } } diff --git a/src/response.rs b/src/response.rs index 2cea7d73..f4f11cfe 100644 --- a/src/response.rs +++ b/src/response.rs @@ -79,7 +79,7 @@ pub struct Response { /// The socket address of the server that sent the response. pub(crate) remote_addr: SocketAddr, /// The socket address of the client that sent the request. - pub(crate) local_addr: Option, + pub(crate) local_addr: SocketAddr, /// The redirect history of this response, if any. The history starts with /// the first response received and ends with the response immediately /// previous to this one. @@ -235,7 +235,7 @@ impl Response { } /// The local address the request was made from. - pub fn local_addr(&self) -> Option { + pub fn local_addr(&self) -> SocketAddr { self.local_addr } @@ -541,7 +541,10 @@ impl Response { pub(crate) fn do_from_stream(stream: Stream, unit: Unit) -> Result { let remote_addr = stream.remote_addr; - let local_addr = stream.socket().map(|s| s.local_addr().unwrap()); + let local_addr = match stream.socket() { + Some(sock) => sock.local_addr().map_err(|e| Error::from(e))?, + None => std::net::SocketAddrV4::new(std::net::Ipv4Addr::new(127, 0, 0, 1), 0).into(), + }; // // HTTP/1.1 200 OK\r\n