mirror of
https://github.com/tokio-rs/axum.git
synced 2026-09-02 00:00:22 +02:00
@@ -138,7 +138,7 @@
|
|||||||
#![cfg_attr(test, allow(clippy::float_cmp))]
|
#![cfg_attr(test, allow(clippy::float_cmp))]
|
||||||
|
|
||||||
use axum::{
|
use axum::{
|
||||||
body::{box_body, BoxBody, Bytes, Full, HttpBody},
|
body::{boxed, BoxBody, Bytes, Full, HttpBody},
|
||||||
extract::{FromRequest, RequestParts},
|
extract::{FromRequest, RequestParts},
|
||||||
http::{Request, Response, StatusCode},
|
http::{Request, Response, StatusCode},
|
||||||
response::IntoResponse,
|
response::IntoResponse,
|
||||||
@@ -281,8 +281,8 @@ where
|
|||||||
|
|
||||||
let future = Box::pin(async move {
|
let future = Box::pin(async move {
|
||||||
match inner.oneshot(req).await {
|
match inner.oneshot(req).await {
|
||||||
Ok(res) => Ok(res.map(box_body)),
|
Ok(res) => Ok(res.map(boxed)),
|
||||||
Err(err) => Ok(f(err).await.into_response().map(box_body)),
|
Err(err) => Ok(f(err).await.into_response().map(boxed)),
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -329,7 +329,7 @@ macro_rules! impl_service {
|
|||||||
$(
|
$(
|
||||||
let $ty = match $ty::from_request(&mut req).await {
|
let $ty = match $ty::from_request(&mut req).await {
|
||||||
Ok(value) => value,
|
Ok(value) => value,
|
||||||
Err(rejection) => return Ok(rejection.into_response().map(box_body)),
|
Err(rejection) => return Ok(rejection.into_response().map(boxed)),
|
||||||
};
|
};
|
||||||
)*
|
)*
|
||||||
|
|
||||||
@@ -338,14 +338,14 @@ macro_rules! impl_service {
|
|||||||
Err(err) => {
|
Err(err) => {
|
||||||
return Ok(Response::builder()
|
return Ok(Response::builder()
|
||||||
.status(StatusCode::INTERNAL_SERVER_ERROR)
|
.status(StatusCode::INTERNAL_SERVER_ERROR)
|
||||||
.body(box_body(Full::from(err.to_string())))
|
.body(boxed(Full::from(err.to_string())))
|
||||||
.unwrap());
|
.unwrap());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
match inner.oneshot(req).await {
|
match inner.oneshot(req).await {
|
||||||
Ok(res) => Ok(res.map(box_body)),
|
Ok(res) => Ok(res.map(boxed)),
|
||||||
Err(err) => Ok(f($($ty),*, err).await.into_response().map(box_body)),
|
Err(err) => Ok(f($($ty),*, err).await.into_response().map(boxed)),
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
+3
-2
@@ -7,7 +7,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||||||
|
|
||||||
# Unreleased
|
# Unreleased
|
||||||
|
|
||||||
- None.
|
- **change:** `box_body` has been renamed to `boxed`. `box_body` still exists
|
||||||
|
but is deprecated.
|
||||||
|
|
||||||
# 0.3.3 (13. November, 2021)
|
# 0.3.3 (13. November, 2021)
|
||||||
|
|
||||||
@@ -490,7 +491,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||||||
- Improve error message of `MissingExtension` rejections ([#72](https://github.com/tokio-rs/axum/pull/72))
|
- Improve error message of `MissingExtension` rejections ([#72](https://github.com/tokio-rs/axum/pull/72))
|
||||||
- Improve documentation for routing ([#71](https://github.com/tokio-rs/axum/pull/71))
|
- Improve documentation for routing ([#71](https://github.com/tokio-rs/axum/pull/71))
|
||||||
- Clarify required response body type when routing to `tower::Service`s ([#69](https://github.com/tokio-rs/axum/pull/69))
|
- Clarify required response body type when routing to `tower::Service`s ([#69](https://github.com/tokio-rs/axum/pull/69))
|
||||||
- Add `axum::body::box_body` to converting an `http_body::Body` to `axum::body::BoxBody` ([#69](https://github.com/tokio-rs/axum/pull/69))
|
- Add `axum::body::boxed` to converting an `http_body::Body` to `axum::body::BoxBody` ([#69](https://github.com/tokio-rs/axum/pull/69))
|
||||||
- Add `axum::sse` for Server-Sent Events ([#75](https://github.com/tokio-rs/axum/pull/75))
|
- Add `axum::sse` for Server-Sent Events ([#75](https://github.com/tokio-rs/axum/pull/75))
|
||||||
- Mention required dependencies in docs ([#77](https://github.com/tokio-rs/axum/pull/77))
|
- Mention required dependencies in docs ([#77](https://github.com/tokio-rs/axum/pull/77))
|
||||||
- Fix WebSockets failing on Firefox ([#76](https://github.com/tokio-rs/axum/pull/76))
|
- Fix WebSockets failing on Firefox ([#76](https://github.com/tokio-rs/axum/pull/76))
|
||||||
|
|||||||
+11
-1
@@ -22,7 +22,17 @@ pub use bytes::Bytes;
|
|||||||
pub type BoxBody = http_body::combinators::UnsyncBoxBody<Bytes, Error>;
|
pub type BoxBody = http_body::combinators::UnsyncBoxBody<Bytes, Error>;
|
||||||
|
|
||||||
/// Convert a [`http_body::Body`] into a [`BoxBody`].
|
/// Convert a [`http_body::Body`] into a [`BoxBody`].
|
||||||
|
#[deprecated(note = "use `axum::body::boxed`", since = "0.3.4")]
|
||||||
pub fn box_body<B>(body: B) -> BoxBody
|
pub fn box_body<B>(body: B) -> BoxBody
|
||||||
|
where
|
||||||
|
B: http_body::Body<Data = Bytes> + Send + 'static,
|
||||||
|
B::Error: Into<BoxError>,
|
||||||
|
{
|
||||||
|
boxed(body)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Convert a [`http_body::Body`] into a [`BoxBody`].
|
||||||
|
pub fn boxed<B>(body: B) -> BoxBody
|
||||||
where
|
where
|
||||||
B: http_body::Body<Data = Bytes> + Send + 'static,
|
B: http_body::Body<Data = Bytes> + Send + 'static,
|
||||||
B::Error: Into<BoxError>,
|
B::Error: Into<BoxError>,
|
||||||
@@ -31,5 +41,5 @@ where
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn empty() -> BoxBody {
|
pub(crate) fn empty() -> BoxBody {
|
||||||
box_body(http_body::Empty::new())
|
boxed(http_body::Empty::new())
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -138,7 +138,7 @@ let app = Router::new()
|
|||||||
// it can be routed to directly.
|
// it can be routed to directly.
|
||||||
service_fn(|req: Request<Body>| async move {
|
service_fn(|req: Request<Body>| async move {
|
||||||
let body = Body::from(format!("Hi from `{} /foo`", req.method()));
|
let body = Body::from(format!("Hi from `{} /foo`", req.method()));
|
||||||
let body = axum::body::box_body(body);
|
let body = axum::body::boxed(body);
|
||||||
let res = Response::new(body);
|
let res = Response::new(body);
|
||||||
Ok::<_, Infallible>(res)
|
Ok::<_, Infallible>(res)
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -151,7 +151,7 @@ pub mod future {
|
|||||||
//! Future types.
|
//! Future types.
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
body::{box_body, BoxBody},
|
body::{boxed, BoxBody},
|
||||||
response::IntoResponse,
|
response::IntoResponse,
|
||||||
BoxError,
|
BoxError,
|
||||||
};
|
};
|
||||||
@@ -190,11 +190,11 @@ pub mod future {
|
|||||||
let this = self.project();
|
let this = self.project();
|
||||||
|
|
||||||
match ready!(this.inner.poll(cx)) {
|
match ready!(this.inner.poll(cx)) {
|
||||||
Ok(res) => Ok(res.map(box_body)).into(),
|
Ok(res) => Ok(res.map(boxed)).into(),
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
let f = this.f.take().unwrap();
|
let f = this.f.take().unwrap();
|
||||||
let res = f(err);
|
let res = f(err);
|
||||||
Ok(res.into_response().map(box_body)).into()
|
Ok(res.into_response().map(boxed)).into()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -247,7 +247,7 @@ where
|
|||||||
State::Call { future }
|
State::Call { future }
|
||||||
}
|
}
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
let res = err.into_response().map(crate::body::box_body);
|
let res = err.into_response().map(crate::body::boxed);
|
||||||
return Poll::Ready(Ok(res));
|
return Poll::Ready(Ok(res));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -255,7 +255,7 @@ where
|
|||||||
StateProj::Call { future } => {
|
StateProj::Call { future } => {
|
||||||
return future
|
return future
|
||||||
.poll(cx)
|
.poll(cx)
|
||||||
.map(|result| result.map(|response| response.map(crate::body::box_body)));
|
.map(|result| result.map(|response| response.map(crate::body::boxed)));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
use super::IntoResponse;
|
use super::IntoResponse;
|
||||||
use crate::{
|
use crate::{
|
||||||
body::{box_body, BoxBody},
|
body::{boxed, BoxBody},
|
||||||
BoxError, Error,
|
BoxError, Error,
|
||||||
};
|
};
|
||||||
use bytes::Bytes;
|
use bytes::Bytes;
|
||||||
@@ -325,10 +325,10 @@ where
|
|||||||
|
|
||||||
fn into_response(self) -> http::Response<Self::Body> {
|
fn into_response(self) -> http::Response<Self::Body> {
|
||||||
match self {
|
match self {
|
||||||
Self::PayloadTooLarge(inner) => inner.into_response().map(box_body),
|
Self::PayloadTooLarge(inner) => inner.into_response().map(boxed),
|
||||||
Self::LengthRequired(inner) => inner.into_response().map(box_body),
|
Self::LengthRequired(inner) => inner.into_response().map(boxed),
|
||||||
Self::HeadersAlreadyExtracted(inner) => inner.into_response().map(box_body),
|
Self::HeadersAlreadyExtracted(inner) => inner.into_response().map(boxed),
|
||||||
Self::Inner(inner) => inner.into_response().map(box_body),
|
Self::Inner(inner) => inner.into_response().map(boxed),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
use super::{FromRequest, RequestParts};
|
use super::{FromRequest, RequestParts};
|
||||||
use crate::{
|
use crate::{
|
||||||
body::{box_body, BoxBody},
|
body::{boxed, BoxBody},
|
||||||
response::IntoResponse,
|
response::IntoResponse,
|
||||||
};
|
};
|
||||||
use async_trait::async_trait;
|
use async_trait::async_trait;
|
||||||
@@ -33,7 +33,7 @@ macro_rules! impl_from_request {
|
|||||||
type Rejection = Response<BoxBody>;
|
type Rejection = Response<BoxBody>;
|
||||||
|
|
||||||
async fn from_request(req: &mut RequestParts<B>) -> Result<Self, Self::Rejection> {
|
async fn from_request(req: &mut RequestParts<B>) -> Result<Self, Self::Rejection> {
|
||||||
$( let $ty = $ty::from_request(req).await.map_err(|err| err.into_response().map(box_body))?; )*
|
$( let $ty = $ty::from_request(req).await.map_err(|err| err.into_response().map(boxed))?; )*
|
||||||
Ok(($($ty,)*))
|
Ok(($($ty,)*))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -71,7 +71,7 @@
|
|||||||
//! [axum-debug]: https://docs.rs/axum-debug
|
//! [axum-debug]: https://docs.rs/axum-debug
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
body::{box_body, BoxBody},
|
body::{boxed, BoxBody},
|
||||||
extract::{
|
extract::{
|
||||||
connect_info::{Connected, IntoMakeServiceWithConnectInfo},
|
connect_info::{Connected, IntoMakeServiceWithConnectInfo},
|
||||||
FromRequest, RequestParts,
|
FromRequest, RequestParts,
|
||||||
@@ -272,7 +272,7 @@ where
|
|||||||
type Sealed = sealed::Hidden;
|
type Sealed = sealed::Hidden;
|
||||||
|
|
||||||
async fn call(self, _req: Request<B>) -> Response<BoxBody> {
|
async fn call(self, _req: Request<B>) -> Response<BoxBody> {
|
||||||
self().await.into_response().map(box_body)
|
self().await.into_response().map(boxed)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -296,13 +296,13 @@ macro_rules! impl_handler {
|
|||||||
$(
|
$(
|
||||||
let $ty = match $ty::from_request(&mut req).await {
|
let $ty = match $ty::from_request(&mut req).await {
|
||||||
Ok(value) => value,
|
Ok(value) => value,
|
||||||
Err(rejection) => return rejection.into_response().map(box_body),
|
Err(rejection) => return rejection.into_response().map(boxed),
|
||||||
};
|
};
|
||||||
)*
|
)*
|
||||||
|
|
||||||
let res = self($($ty,)*).await;
|
let res = self($($ty,)*).await;
|
||||||
|
|
||||||
res.into_response().map(box_body)
|
res.into_response().map(boxed)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -371,8 +371,8 @@ where
|
|||||||
.await
|
.await
|
||||||
.map_err(IntoResponse::into_response)
|
.map_err(IntoResponse::into_response)
|
||||||
{
|
{
|
||||||
Ok(res) => res.map(box_body),
|
Ok(res) => res.map(boxed),
|
||||||
Err(res) => res.map(box_body),
|
Err(res) => res.map(boxed),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
use super::IntoResponse;
|
use super::IntoResponse;
|
||||||
use crate::{
|
use crate::{
|
||||||
body::{box_body, BoxBody},
|
body::{boxed, BoxBody},
|
||||||
BoxError,
|
BoxError,
|
||||||
};
|
};
|
||||||
use bytes::Bytes;
|
use bytes::Bytes;
|
||||||
@@ -133,10 +133,10 @@ where
|
|||||||
fn into_response(self) -> Response<Self::Body> {
|
fn into_response(self) -> Response<Self::Body> {
|
||||||
let headers = match self.0.try_into_header_map() {
|
let headers = match self.0.try_into_header_map() {
|
||||||
Ok(headers) => headers,
|
Ok(headers) => headers,
|
||||||
Err(res) => return res.map(box_body),
|
Err(res) => return res.map(boxed),
|
||||||
};
|
};
|
||||||
|
|
||||||
(headers, self.1).into_response().map(box_body)
|
(headers, self.1).into_response().map(boxed)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -157,10 +157,10 @@ where
|
|||||||
fn into_response(self) -> Response<Self::Body> {
|
fn into_response(self) -> Response<Self::Body> {
|
||||||
let headers = match self.1.try_into_header_map() {
|
let headers = match self.1.try_into_header_map() {
|
||||||
Ok(headers) => headers,
|
Ok(headers) => headers,
|
||||||
Err(res) => return res.map(box_body),
|
Err(res) => return res.map(boxed),
|
||||||
};
|
};
|
||||||
|
|
||||||
(self.0, headers, self.2).into_response().map(box_body)
|
(self.0, headers, self.2).into_response().map(boxed)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
#![doc = include_str!("../docs/response.md")]
|
#![doc = include_str!("../docs/response.md")]
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
body::{box_body, BoxBody},
|
body::{boxed, BoxBody},
|
||||||
BoxError, Error,
|
BoxError, Error,
|
||||||
};
|
};
|
||||||
use bytes::Bytes;
|
use bytes::Bytes;
|
||||||
@@ -157,7 +157,7 @@ pub trait IntoResponse {
|
|||||||
/// contains exactly one chunk.
|
/// contains exactly one chunk.
|
||||||
/// - [`axum::body::BoxBody`]: If you need to unify multiple body types into
|
/// - [`axum::body::BoxBody`]: If you need to unify multiple body types into
|
||||||
/// one, or return a body type that cannot be named. Can be created with
|
/// one, or return a body type that cannot be named. Can be created with
|
||||||
/// [`box_body`].
|
/// [`boxed`].
|
||||||
///
|
///
|
||||||
/// [`axum::body::Body`]: crate::body::Body
|
/// [`axum::body::Body`]: crate::body::Body
|
||||||
/// [`axum::body::Empty<Bytes>`]: crate::body::Empty
|
/// [`axum::body::Empty<Bytes>`]: crate::body::Empty
|
||||||
@@ -209,8 +209,8 @@ where
|
|||||||
|
|
||||||
fn into_response(self) -> Response<Self::Body> {
|
fn into_response(self) -> Response<Self::Body> {
|
||||||
match self {
|
match self {
|
||||||
Ok(value) => value.into_response().map(box_body),
|
Ok(value) => value.into_response().map(boxed),
|
||||||
Err(err) => err.into_response().map(box_body),
|
Err(err) => err.into_response().map(boxed),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
//! Routing for handlers based on HTTP methods.
|
//! Routing for handlers based on HTTP methods.
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
body::{box_body, BoxBody},
|
body::{boxed, BoxBody},
|
||||||
handler::Handler,
|
handler::Handler,
|
||||||
routing::{MethodFilter, MethodNotAllowed},
|
routing::{MethodFilter, MethodNotAllowed},
|
||||||
util::{Either, EitherProj},
|
util::{Either, EitherProj},
|
||||||
@@ -446,7 +446,7 @@ where
|
|||||||
};
|
};
|
||||||
|
|
||||||
if this.req_method == &Method::HEAD {
|
if this.req_method == &Method::HEAD {
|
||||||
let response = response.map(|_| box_body(Empty::new()));
|
let response = response.map(|_| boxed(Empty::new()));
|
||||||
Poll::Ready(Ok(response))
|
Poll::Ready(Ok(response))
|
||||||
} else {
|
} else {
|
||||||
Poll::Ready(Ok(response))
|
Poll::Ready(Ok(response))
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
use self::{future::RouterFuture, not_found::NotFound};
|
use self::{future::RouterFuture, not_found::NotFound};
|
||||||
use crate::{
|
use crate::{
|
||||||
body::{box_body, Body, BoxBody},
|
body::{boxed, Body, BoxBody},
|
||||||
extract::{
|
extract::{
|
||||||
connect_info::{Connected, IntoMakeServiceWithConnectInfo},
|
connect_info::{Connected, IntoMakeServiceWithConnectInfo},
|
||||||
MatchedPath, OriginalUri,
|
MatchedPath, OriginalUri,
|
||||||
@@ -249,7 +249,7 @@ where
|
|||||||
{
|
{
|
||||||
let layer = ServiceBuilder::new()
|
let layer = ServiceBuilder::new()
|
||||||
.layer_fn(Route::new)
|
.layer_fn(Route::new)
|
||||||
.layer(MapResponseBodyLayer::new(box_body))
|
.layer(MapResponseBodyLayer::new(boxed))
|
||||||
.layer(layer);
|
.layer(layer);
|
||||||
|
|
||||||
let routes = self
|
let routes = self
|
||||||
@@ -285,7 +285,7 @@ where
|
|||||||
{
|
{
|
||||||
let layer = ServiceBuilder::new()
|
let layer = ServiceBuilder::new()
|
||||||
.layer_fn(Route::new)
|
.layer_fn(Route::new)
|
||||||
.layer(MapResponseBodyLayer::new(box_body))
|
.layer(MapResponseBodyLayer::new(boxed))
|
||||||
.layer(layer);
|
.layer(layer);
|
||||||
|
|
||||||
let routes = self
|
let routes = self
|
||||||
|
|||||||
@@ -97,7 +97,7 @@
|
|||||||
//! [`Service`'s]: tower::Service
|
//! [`Service`'s]: tower::Service
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
body::{box_body, BoxBody},
|
body::{boxed, BoxBody},
|
||||||
routing::{MethodFilter, MethodNotAllowed},
|
routing::{MethodFilter, MethodNotAllowed},
|
||||||
util::{Either, EitherProj},
|
util::{Either, EitherProj},
|
||||||
BoxError,
|
BoxError,
|
||||||
@@ -537,12 +537,12 @@ where
|
|||||||
let this = self.project();
|
let this = self.project();
|
||||||
|
|
||||||
let response = match this.inner.project() {
|
let response = match this.inner.project() {
|
||||||
EitherProj::A { inner } => ready!(inner.poll(cx))?.map(box_body),
|
EitherProj::A { inner } => ready!(inner.poll(cx))?.map(boxed),
|
||||||
EitherProj::B { inner } => ready!(inner.poll(cx))?,
|
EitherProj::B { inner } => ready!(inner.poll(cx))?,
|
||||||
};
|
};
|
||||||
|
|
||||||
if this.req_method == &Method::HEAD {
|
if this.req_method == &Method::HEAD {
|
||||||
let response = response.map(|_| box_body(Empty::new()));
|
let response = response.map(|_| boxed(Empty::new()));
|
||||||
Poll::Ready(Ok(response))
|
Poll::Ready(Ok(response))
|
||||||
} else {
|
} else {
|
||||||
Poll::Ready(Ok(response))
|
Poll::Ready(Ok(response))
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
use super::*;
|
use super::*;
|
||||||
use crate::{body::box_body, error_handling::HandleErrorExt, extract::Extension};
|
use crate::{body::boxed, error_handling::HandleErrorExt, extract::Extension};
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
@@ -149,7 +149,7 @@ async fn nested_service_sees_stripped_uri() {
|
|||||||
Router::new().route(
|
Router::new().route(
|
||||||
"/baz",
|
"/baz",
|
||||||
service_fn(|req: Request<Body>| async move {
|
service_fn(|req: Request<Body>| async move {
|
||||||
let body = box_body(Body::from(req.uri().to_string()));
|
let body = boxed(Body::from(req.uri().to_string()));
|
||||||
Ok::<_, Infallible>(Response::new(body))
|
Ok::<_, Infallible>(Response::new(body))
|
||||||
}),
|
}),
|
||||||
),
|
),
|
||||||
|
|||||||
@@ -13,7 +13,7 @@
|
|||||||
//! Example is based on <https://github.com/hyperium/hyper/blob/master/examples/http_proxy.rs>
|
//! Example is based on <https://github.com/hyperium/hyper/blob/master/examples/http_proxy.rs>
|
||||||
|
|
||||||
use axum::{
|
use axum::{
|
||||||
body::{box_body, Body},
|
body::{boxed, Body},
|
||||||
http::{Method, Request, Response, StatusCode},
|
http::{Method, Request, Response, StatusCode},
|
||||||
routing::get,
|
routing::get,
|
||||||
Router,
|
Router,
|
||||||
@@ -37,7 +37,7 @@ async fn main() {
|
|||||||
let router = router.clone();
|
let router = router.clone();
|
||||||
async move {
|
async move {
|
||||||
if req.method() == Method::CONNECT {
|
if req.method() == Method::CONNECT {
|
||||||
proxy(req).await.map(|res| res.map(box_body))
|
proxy(req).await.map(|res| res.map(boxed))
|
||||||
} else {
|
} else {
|
||||||
router.oneshot(req).await.map_err(|err| match err {})
|
router.oneshot(req).await.map_err(|err| match err {})
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user