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, Headers, impl IntoResponse) to customize
the status code and headers.
Tuple Fields
0: HTrait Implementations
sourceimpl<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, 
sourcefn into_response(self) -> Response
 
fn into_response(self) -> Response
Create a response.
impl<H: Copy> Copy for Headers<H>
Auto Trait Implementations
impl<H> RefUnwindSafe for Headers<H> where
    H: RefUnwindSafe, 
impl<H> Send for Headers<H> where
    H: Send, 
impl<H> Sync for Headers<H> where
    H: Sync, 
impl<H> Unpin for Headers<H> where
    H: Unpin, 
impl<H> UnwindSafe for Headers<H> where
    H: UnwindSafe, 
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
    T: ?Sized, 
 
impl<T> BorrowMut<T> for T where
    T: ?Sized, 
const: unstable · sourcepub fn borrow_mut(&mut self) -> &mut T
 
pub fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> ToOwned for T where
    T: Clone, 
 
impl<T> ToOwned for T where
    T: Clone, 
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcepub fn to_owned(&self) -> T
 
pub fn to_owned(&self) -> T
Creates owned data from borrowed data, usually by cloning. Read more
sourcepub fn clone_into(&self, target: &mut T)
 
pub fn clone_into(&self, target: &mut T)
🔬 This is a nightly-only experimental API. (
toowned_clone_into)Uses borrowed data to replace owned data, usually by cloning. Read more