Skip to content

Commit

Permalink
remove the Option from local_addr, replace unwrap()
Browse files Browse the repository at this point in the history
  • Loading branch information
kubuzetto authored and algesten committed May 12, 2023
1 parent c305b91 commit cd70959
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/http_interop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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![],
}
}
Expand Down
9 changes: 6 additions & 3 deletions src/response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
}

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit cd70959

Please sign in to comment.