src/server/rest.rs: avoid unwrap
This commit is contained in:
parent
7fb4f5642a
commit
80af046794
@ -49,9 +49,15 @@ impl MakeService<&tokio_openssl::SslStream<tokio::net::TcpStream>> for RestServe
|
|||||||
type Service = ApiService;
|
type Service = ApiService;
|
||||||
type Future = Box<dyn Future<Item = Self::Service, Error = Self::MakeError> + Send>;
|
type Future = Box<dyn Future<Item = Self::Service, Error = Self::MakeError> + Send>;
|
||||||
fn make_service(&mut self, ctx: &tokio_openssl::SslStream<tokio::net::TcpStream>) -> Self::Future {
|
fn make_service(&mut self, ctx: &tokio_openssl::SslStream<tokio::net::TcpStream>) -> Self::Future {
|
||||||
let peer = ctx.get_ref().get_ref().peer_addr().unwrap();
|
match ctx.get_ref().get_ref().peer_addr() {
|
||||||
|
Err(err) => {
|
||||||
|
Box::new(future::err(format_err!("unable to get peer address - {}", err)))
|
||||||
|
}
|
||||||
|
Ok(peer) => {
|
||||||
Box::new(future::ok(ApiService { peer, api_config: self.api_config.clone() }))
|
Box::new(future::ok(ApiService { peer, api_config: self.api_config.clone() }))
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl MakeService<&tokio::net::TcpStream> for RestServer
|
impl MakeService<&tokio::net::TcpStream> for RestServer
|
||||||
@ -63,9 +69,15 @@ impl MakeService<&tokio::net::TcpStream> for RestServer
|
|||||||
type Service = ApiService;
|
type Service = ApiService;
|
||||||
type Future = Box<dyn Future<Item = Self::Service, Error = Self::MakeError> + Send>;
|
type Future = Box<dyn Future<Item = Self::Service, Error = Self::MakeError> + Send>;
|
||||||
fn make_service(&mut self, ctx: &tokio::net::TcpStream) -> Self::Future {
|
fn make_service(&mut self, ctx: &tokio::net::TcpStream) -> Self::Future {
|
||||||
let peer = ctx.peer_addr().unwrap();
|
match ctx.peer_addr() {
|
||||||
|
Err(err) => {
|
||||||
|
Box::new(future::err(format_err!("unable to get peer address - {}", err)))
|
||||||
|
}
|
||||||
|
Ok(peer) => {
|
||||||
Box::new(future::ok(ApiService { peer, api_config: self.api_config.clone() }))
|
Box::new(future::ok(ApiService { peer, api_config: self.api_config.clone() }))
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user