axum_extra/response/
mod.rs1#[cfg(any(feature = "attachment", feature = "file-stream"))]
4mod content_disposition;
5
6#[cfg(feature = "erased-json")]
7mod erased_json;
8
9#[cfg(feature = "attachment")]
10mod attachment;
11
12#[cfg(feature = "multipart")]
13pub mod multiple;
14
15#[cfg(feature = "error-response")]
16mod error_response;
17
18#[cfg(feature = "file-stream")]
19pub mod file_stream;
21
22#[cfg(feature = "file-stream")]
23pub use file_stream::FileStream;
24
25#[cfg(feature = "error-response")]
26pub use error_response::InternalServerError;
27
28#[cfg(feature = "erased-json")]
29pub use erased_json::ErasedJson;
30
31#[cfg(feature = "erased-json")]
33#[doc(hidden)]
34pub use erased_json::private as __private_erased_json;
35
36#[cfg(feature = "json-lines")]
37#[doc(no_inline)]
38pub use crate::json_lines::JsonLines;
39
40#[cfg(feature = "attachment")]
41pub use attachment::Attachment;
42
43macro_rules! mime_response {
44 (
45 $(#[$m:meta])*
46 $ident:ident,
47 $mime:ident,
48 ) => {
49 mime_response! {
50 $(#[$m])*
51 $ident,
52 mime::$mime.as_ref(),
53 }
54 };
55
56 (
57 $(#[$m:meta])*
58 $ident:ident,
59 $mime:expr,
60 ) => {
61 $(#[$m])*
62 #[derive(Clone, Copy, Debug)]
63 #[must_use]
64 pub struct $ident<T>(pub T);
65
66 impl<T> axum_core::response::IntoResponse for $ident<T>
67 where
68 T: axum_core::response::IntoResponse,
69 {
70 fn into_response(self) -> axum_core::response::Response {
71 (
72 [(
73 http::header::CONTENT_TYPE,
74 http::HeaderValue::from_static($mime),
75 )],
76 self.0,
77 )
78 .into_response()
79 }
80 }
81
82 impl<T> From<T> for $ident<T> {
83 fn from(inner: T) -> Self {
84 Self(inner)
85 }
86 }
87 };
88}
89
90mime_response! {
91 JavaScript,
95 APPLICATION_JAVASCRIPT_UTF_8,
96}
97
98mime_response! {
99 Css,
103 TEXT_CSS_UTF_8,
104}
105
106mime_response! {
107 Wasm,
111 "application/wasm",
112}
113
114#[cfg(feature = "typed-header")]
115#[doc(no_inline)]
116pub use crate::typed_header::TypedHeader;