remove the Option from local_addr, replace unwrap()

This commit is contained in:
Devrim Şahin
2023-04-21 12:37:16 +03:00
committed by Martin Algesten
parent c305b915f8
commit cd70959360
2 changed files with 7 additions and 4 deletions

View File

@@ -48,7 +48,7 @@ impl<T: AsRef<[u8]> + Send + Sync + 'static> From<http::Response<T>> for Respons
.collect::<Vec<_>>(),
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![],
}
}

View File

@@ -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<SocketAddr>,
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<SocketAddr> {
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<Response, Error> {
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