remove the Option from local_addr, replace unwrap()
This commit is contained in:
committed by
Martin Algesten
parent
c305b915f8
commit
cd70959360
@@ -48,7 +48,7 @@ impl<T: AsRef<[u8]> + Send + Sync + 'static> From<http::Response<T>> for Respons
|
|||||||
.collect::<Vec<_>>(),
|
.collect::<Vec<_>>(),
|
||||||
reader: Box::new(Cursor::new(value.into_body())),
|
reader: Box::new(Cursor::new(value.into_body())),
|
||||||
remote_addr: SocketAddr::new(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)), 80),
|
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![],
|
history: vec![],
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -79,7 +79,7 @@ pub struct Response {
|
|||||||
/// The socket address of the server that sent the response.
|
/// The socket address of the server that sent the response.
|
||||||
pub(crate) remote_addr: SocketAddr,
|
pub(crate) remote_addr: SocketAddr,
|
||||||
/// The socket address of the client that sent the request.
|
/// 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 redirect history of this response, if any. The history starts with
|
||||||
/// the first response received and ends with the response immediately
|
/// the first response received and ends with the response immediately
|
||||||
/// previous to this one.
|
/// previous to this one.
|
||||||
@@ -235,7 +235,7 @@ impl Response {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// The local address the request was made from.
|
/// The local address the request was made from.
|
||||||
pub fn local_addr(&self) -> Option<SocketAddr> {
|
pub fn local_addr(&self) -> SocketAddr {
|
||||||
self.local_addr
|
self.local_addr
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -541,7 +541,10 @@ impl Response {
|
|||||||
pub(crate) fn do_from_stream(stream: Stream, unit: Unit) -> Result<Response, Error> {
|
pub(crate) fn do_from_stream(stream: Stream, unit: Unit) -> Result<Response, Error> {
|
||||||
let remote_addr = stream.remote_addr;
|
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
|
// HTTP/1.1 200 OK\r\n
|
||||||
|
|||||||
Reference in New Issue
Block a user