mirror of
https://github.com/tokio-rs/axum.git
synced 2024-11-22 07:08:16 +01:00
Remove unwrap from example-reverse-proxy
This commit is contained in:
parent
b1b0e45683
commit
99e8828df5
1 changed files with 7 additions and 3 deletions
|
@ -15,7 +15,7 @@ use axum::{
|
||||||
routing::get,
|
routing::get,
|
||||||
Router,
|
Router,
|
||||||
};
|
};
|
||||||
use hyper::client::HttpConnector;
|
use hyper::{client::HttpConnector, StatusCode};
|
||||||
|
|
||||||
type Client = hyper::client::Client<HttpConnector, Body>;
|
type Client = hyper::client::Client<HttpConnector, Body>;
|
||||||
|
|
||||||
|
@ -34,7 +34,7 @@ async fn main() {
|
||||||
axum::serve(listener, app).await.unwrap();
|
axum::serve(listener, app).await.unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn handler(State(client): State<Client>, mut req: Request) -> Response {
|
async fn handler(State(client): State<Client>, mut req: Request) -> Result<Response, StatusCode> {
|
||||||
let path = req.uri().path();
|
let path = req.uri().path();
|
||||||
let path_query = req
|
let path_query = req
|
||||||
.uri()
|
.uri()
|
||||||
|
@ -46,7 +46,11 @@ async fn handler(State(client): State<Client>, mut req: Request) -> Response {
|
||||||
|
|
||||||
*req.uri_mut() = Uri::try_from(uri).unwrap();
|
*req.uri_mut() = Uri::try_from(uri).unwrap();
|
||||||
|
|
||||||
client.request(req).await.unwrap().into_response()
|
Ok(client
|
||||||
|
.request(req)
|
||||||
|
.await
|
||||||
|
.map_err(|_| StatusCode::BAD_REQUEST)?
|
||||||
|
.into_response())
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn server() {
|
async fn server() {
|
||||||
|
|
Loading…
Reference in a new issue