@@ -11,7 +11,7 @@ use crate::{
1111use bytes:: Bytes ;
1212use http:: {
1313 header:: { self , HeaderMap , HeaderValue } ,
14- Response , StatusCode ,
14+ StatusCode ,
1515} ;
1616use http_body:: {
1717 combinators:: { MapData , MapErr } ,
@@ -24,6 +24,10 @@ mod headers;
2424#[ doc( inline) ]
2525pub use self :: headers:: Headers ;
2626
27+ /// Type alias for [`http::Response`] whose body type defaults to [`BoxBody`], the most common body
28+ /// type used with Axum.
29+ pub type Response < T = BoxBody > = http:: Response < T > ;
30+
2731/// Trait for generating responses.
2832///
2933/// Types that implement `IntoResponse` can be returned from handlers.
@@ -39,10 +43,10 @@ pub use self::headers::Headers;
3943/// ```rust
4044/// use axum::{
4145/// Router,
42- /// body::{self, BoxBody, Bytes},
46+ /// body::{self, Bytes},
4347/// routing::get,
44- /// http::{Response, StatusCode} ,
45- /// response::IntoResponse,
48+ /// http::StatusCode,
49+ /// response::{ IntoResponse, Response} ,
4650/// };
4751///
4852/// enum MyError {
@@ -51,7 +55,7 @@ pub use self::headers::Headers;
5155/// }
5256///
5357/// impl IntoResponse for MyError {
54- /// fn into_response(self) -> Response<BoxBody> {
58+ /// fn into_response(self) -> Response {
5559/// let body = match self {
5660/// MyError::SomethingWentWrong => {
5761/// body::boxed(body::Full::from("something went wrong"))
@@ -84,13 +88,13 @@ pub use self::headers::Headers;
8488///
8589/// ```rust
8690/// use axum::{
87- /// body::{self, BoxBody} ,
91+ /// body,
8892/// routing::get,
89- /// response::IntoResponse,
93+ /// response::{ IntoResponse, Response} ,
9094/// Router,
9195/// };
9296/// use http_body::Body;
93- /// use http::{Response, HeaderMap} ;
97+ /// use http::HeaderMap;
9498/// use bytes::Bytes;
9599/// use std::{
96100/// convert::Infallible,
@@ -125,7 +129,7 @@ pub use self::headers::Headers;
125129///
126130/// // Now we can implement `IntoResponse` directly for `MyBody`
127131/// impl IntoResponse for MyBody {
128- /// fn into_response(self) -> Response<BoxBody> {
132+ /// fn into_response(self) -> Response {
129133/// Response::new(body::boxed(self))
130134/// }
131135/// }
@@ -141,17 +145,17 @@ pub use self::headers::Headers;
141145/// ```
142146pub trait IntoResponse {
143147 /// Create a response.
144- fn into_response ( self ) -> Response < BoxBody > ;
148+ fn into_response ( self ) -> Response ;
145149}
146150
147151impl IntoResponse for ( ) {
148- fn into_response ( self ) -> Response < BoxBody > {
152+ fn into_response ( self ) -> Response {
149153 Response :: new ( boxed ( Empty :: new ( ) ) )
150154 }
151155}
152156
153157impl IntoResponse for Infallible {
154- fn into_response ( self ) -> Response < BoxBody > {
158+ fn into_response ( self ) -> Response {
155159 match self { }
156160 }
157161}
@@ -161,7 +165,7 @@ where
161165 T : IntoResponse ,
162166 E : IntoResponse ,
163167{
164- fn into_response ( self ) -> Response < BoxBody > {
168+ fn into_response ( self ) -> Response {
165169 match self {
166170 Ok ( value) => value. into_response ( ) ,
167171 Err ( err) => err. into_response ( ) ,
@@ -174,15 +178,15 @@ where
174178 B : http_body:: Body < Data = Bytes > + Send + ' static ,
175179 B :: Error : Into < BoxError > ,
176180{
177- fn into_response ( self ) -> Response < BoxBody > {
181+ fn into_response ( self ) -> Response {
178182 self . map ( boxed)
179183 }
180184}
181185
182186macro_rules! impl_into_response_for_body {
183187 ( $body: ty) => {
184188 impl IntoResponse for $body {
185- fn into_response( self ) -> Response < BoxBody > {
189+ fn into_response( self ) -> Response {
186190 Response :: new( boxed( self ) )
187191 }
188192 }
@@ -193,7 +197,7 @@ impl_into_response_for_body!(Full<Bytes>);
193197impl_into_response_for_body ! ( Empty <Bytes >) ;
194198
195199impl IntoResponse for http:: response:: Parts {
196- fn into_response ( self ) -> Response < BoxBody > {
200+ fn into_response ( self ) -> Response {
197201 Response :: from_parts ( self , boxed ( Empty :: new ( ) ) )
198202 }
199203}
@@ -202,7 +206,7 @@ impl<E> IntoResponse for http_body::combinators::BoxBody<Bytes, E>
202206where
203207 E : Into < BoxError > + ' static ,
204208{
205- fn into_response ( self ) -> Response < BoxBody > {
209+ fn into_response ( self ) -> Response {
206210 Response :: new ( boxed ( self ) )
207211 }
208212}
@@ -211,7 +215,7 @@ impl<E> IntoResponse for http_body::combinators::UnsyncBoxBody<Bytes, E>
211215where
212216 E : Into < BoxError > + ' static ,
213217{
214- fn into_response ( self ) -> Response < BoxBody > {
218+ fn into_response ( self ) -> Response {
215219 Response :: new ( boxed ( self ) )
216220 }
217221}
@@ -222,7 +226,7 @@ where
222226 F : FnMut ( B :: Data ) -> Bytes + Send + ' static ,
223227 B :: Error : Into < BoxError > ,
224228{
225- fn into_response ( self ) -> Response < BoxBody > {
229+ fn into_response ( self ) -> Response {
226230 Response :: new ( boxed ( self ) )
227231 }
228232}
@@ -233,27 +237,27 @@ where
233237 F : FnMut ( B :: Error ) -> E + Send + ' static ,
234238 E : Into < BoxError > ,
235239{
236- fn into_response ( self ) -> Response < BoxBody > {
240+ fn into_response ( self ) -> Response {
237241 Response :: new ( boxed ( self ) )
238242 }
239243}
240244
241245impl IntoResponse for & ' static str {
242246 #[ inline]
243- fn into_response ( self ) -> Response < BoxBody > {
247+ fn into_response ( self ) -> Response {
244248 Cow :: Borrowed ( self ) . into_response ( )
245249 }
246250}
247251
248252impl IntoResponse for String {
249253 #[ inline]
250- fn into_response ( self ) -> Response < BoxBody > {
254+ fn into_response ( self ) -> Response {
251255 Cow :: < ' static , str > :: Owned ( self ) . into_response ( )
252256 }
253257}
254258
255259impl IntoResponse for Cow < ' static , str > {
256- fn into_response ( self ) -> Response < BoxBody > {
260+ fn into_response ( self ) -> Response {
257261 let mut res = Response :: new ( boxed ( Full :: from ( self ) ) ) ;
258262 res. headers_mut ( ) . insert (
259263 header:: CONTENT_TYPE ,
@@ -264,7 +268,7 @@ impl IntoResponse for Cow<'static, str> {
264268}
265269
266270impl IntoResponse for Bytes {
267- fn into_response ( self ) -> Response < BoxBody > {
271+ fn into_response ( self ) -> Response {
268272 let mut res = Response :: new ( boxed ( Full :: from ( self ) ) ) ;
269273 res. headers_mut ( ) . insert (
270274 header:: CONTENT_TYPE ,
@@ -275,7 +279,7 @@ impl IntoResponse for Bytes {
275279}
276280
277281impl IntoResponse for & ' static [ u8 ] {
278- fn into_response ( self ) -> Response < BoxBody > {
282+ fn into_response ( self ) -> Response {
279283 let mut res = Response :: new ( boxed ( Full :: from ( self ) ) ) ;
280284 res. headers_mut ( ) . insert (
281285 header:: CONTENT_TYPE ,
@@ -286,7 +290,7 @@ impl IntoResponse for &'static [u8] {
286290}
287291
288292impl IntoResponse for Vec < u8 > {
289- fn into_response ( self ) -> Response < BoxBody > {
293+ fn into_response ( self ) -> Response {
290294 let mut res = Response :: new ( boxed ( Full :: from ( self ) ) ) ;
291295 res. headers_mut ( ) . insert (
292296 header:: CONTENT_TYPE ,
@@ -297,7 +301,7 @@ impl IntoResponse for Vec<u8> {
297301}
298302
299303impl IntoResponse for Cow < ' static , [ u8 ] > {
300- fn into_response ( self ) -> Response < BoxBody > {
304+ fn into_response ( self ) -> Response {
301305 let mut res = Response :: new ( boxed ( Full :: from ( self ) ) ) ;
302306 res. headers_mut ( ) . insert (
303307 header:: CONTENT_TYPE ,
@@ -308,7 +312,7 @@ impl IntoResponse for Cow<'static, [u8]> {
308312}
309313
310314impl IntoResponse for StatusCode {
311- fn into_response ( self ) -> Response < BoxBody > {
315+ fn into_response ( self ) -> Response {
312316 Response :: builder ( )
313317 . status ( self )
314318 . body ( boxed ( Empty :: new ( ) ) )
@@ -320,7 +324,7 @@ impl<T> IntoResponse for (StatusCode, T)
320324where
321325 T : IntoResponse ,
322326{
323- fn into_response ( self ) -> Response < BoxBody > {
327+ fn into_response ( self ) -> Response {
324328 let mut res = self . 1 . into_response ( ) ;
325329 * res. status_mut ( ) = self . 0 ;
326330 res
@@ -331,7 +335,7 @@ impl<T> IntoResponse for (HeaderMap, T)
331335where
332336 T : IntoResponse ,
333337{
334- fn into_response ( self ) -> Response < BoxBody > {
338+ fn into_response ( self ) -> Response {
335339 let mut res = self . 1 . into_response ( ) ;
336340 res. headers_mut ( ) . extend ( self . 0 ) ;
337341 res
@@ -342,7 +346,7 @@ impl<T> IntoResponse for (StatusCode, HeaderMap, T)
342346where
343347 T : IntoResponse ,
344348{
345- fn into_response ( self ) -> Response < BoxBody > {
349+ fn into_response ( self ) -> Response {
346350 let mut res = self . 2 . into_response ( ) ;
347351 * res. status_mut ( ) = self . 0 ;
348352 res. headers_mut ( ) . extend ( self . 1 ) ;
@@ -351,7 +355,7 @@ where
351355}
352356
353357impl IntoResponse for HeaderMap {
354- fn into_response ( self ) -> Response < BoxBody > {
358+ fn into_response ( self ) -> Response {
355359 let mut res = Response :: new ( boxed ( Empty :: new ( ) ) ) ;
356360 * res. headers_mut ( ) = self ;
357361 res
0 commit comments