A "proxy" with axum v0.7 and hyper v1? #2529
Answered
by
davidpdrsn
frederikhors
asked this question in
Q&A
-
SummaryCurrently using axum v0.6.20 and hyper v0.14.28 I have the following code that is work amazingly: #[tokio::main]
async fn main() {
let app = Router::new()
.route("/", get(handler))
.route("/custom/*key", get(proxy).post(proxy));
// ...
}
pub async fn proxy(mut req: Request<Body>) -> Result<Response<Body>, StatusCode> {
let path_query = req
.uri()
.path_and_query()
.map_or_else(|| req.uri().path(), |v| v.as_str());
let uri = format!("http://localhost:9000/{}", path_query);
*req.uri_mut() = Uri::try_from(uri).unwrap();
// This comes from State in real code
let hyper_client = HyperClient::new();
let res = hyper_client.request(req).await.unwrap();
if res.status().is_server_error() {
return Err(StatusCode::INTERNAL_SERVER_ERROR);
}
Ok(res)
} Now with axum v0.7 (and hyper v1) I don't understand anymore if this can continue to work:
What can I do? axum version0.7 |
Beta Was this translation helpful? Give feedback.
Answered by
davidpdrsn
Jan 21, 2024
Replies: 1 comment
-
You can return |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
frederikhors
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You can return
Response<Incoming>
.