Struct axum_core::response::Headers [−][src]
pub struct Headers<H>(pub H);Expand description
A response with headers.
Example
use axum::{
Router,
response::{IntoResponse, Headers},
routing::get,
};
use http::header::{HeaderName, HeaderValue};
// It works with any `IntoIterator<Item = (Key, Value)>` where `Key` can be
// turned into a `HeaderName` and `Value` can be turned into a `HeaderValue`
//
// Such as `Vec<(HeaderName, HeaderValue)>`
async fn just_headers() -> impl IntoResponse {
Headers(vec![
(HeaderName::from_static("X-Foo"), HeaderValue::from_static("foo")),
])
}
// Or `Vec<(&str, &str)>`
async fn from_strings() -> impl IntoResponse {
Headers(vec![("X-Foo", "foo")])
}
// Or `[(&str, &str)]` if you're on Rust 1.53+
let app = Router::new()
.route("/just-headers", get(just_headers))
.route("/from-strings", get(from_strings));If a conversion to HeaderName or HeaderValue fails a 500 Internal Server Error response will be returned.
You can also return (Headers, impl IntoResponse) to customize the headers
of a response, or (StatusCode, Headeres, impl IntoResponse) to customize
the status code and headers.
Tuple Fields
0: HTrait Implementations
impl<H, K, V> IntoResponse for Headers<H> where
H: IntoIterator<Item = (K, V)>,
K: TryInto<HeaderName>,
K::Error: Display,
V: TryInto<HeaderValue>,
V::Error: Display,
impl<H, K, V> IntoResponse for Headers<H> where
H: IntoIterator<Item = (K, V)>,
K: TryInto<HeaderName>,
K::Error: Display,
V: TryInto<HeaderValue>,
V::Error: Display,
Create a response.
Auto Trait Implementations
impl<H> RefUnwindSafe for Headers<H> where
H: RefUnwindSafe,
impl<H> UnwindSafe for Headers<H> where
H: UnwindSafe,
Blanket Implementations
Mutably borrows from an owned value. Read more