axum_core/response/
append_headers.rs
1use super::{IntoResponse, IntoResponseParts, Response, ResponseParts, TryIntoHeaderError};
2use http::header::{HeaderName, HeaderValue};
3use std::fmt;
4
5#[derive(Debug, Clone, Copy)]
33#[must_use]
34pub struct AppendHeaders<I>(pub I);
35
36impl<I, K, V> IntoResponse for AppendHeaders<I>
37where
38 I: IntoIterator<Item = (K, V)>,
39 K: TryInto<HeaderName>,
40 K::Error: fmt::Display,
41 V: TryInto<HeaderValue>,
42 V::Error: fmt::Display,
43{
44 fn into_response(self) -> Response {
45 (self, ()).into_response()
46 }
47}
48
49impl<I, K, V> IntoResponseParts for AppendHeaders<I>
50where
51 I: IntoIterator<Item = (K, V)>,
52 K: TryInto<HeaderName>,
53 K::Error: fmt::Display,
54 V: TryInto<HeaderValue>,
55 V::Error: fmt::Display,
56{
57 type Error = TryIntoHeaderError<K::Error, V::Error>;
58
59 fn into_response_parts(self, mut res: ResponseParts) -> Result<ResponseParts, Self::Error> {
60 for (key, value) in self.0 {
61 let key = key.try_into().map_err(TryIntoHeaderError::key)?;
62 let value = value.try_into().map_err(TryIntoHeaderError::value)?;
63 res.headers_mut().append(key, value);
64 }
65
66 Ok(res)
67 }
68}