mirror of
https://github.com/tokio-rs/axum.git
synced 2026-09-06 00:00:17 +02:00
Fixed the implementation of IntoResponse of (HeaderMap, T) and (StatusCode, HeaderMap, T) would ignore headers from T (#137)
Co-authored-by: David Pedersen <[email protected]>
This commit is contained in:
@@ -13,6 +13,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||||||
- Re-export `http` crate and `hyper::Server`. ([#110](https://github.com/tokio-rs/axum/pull/110))
|
- Re-export `http` crate and `hyper::Server`. ([#110](https://github.com/tokio-rs/axum/pull/110))
|
||||||
- Fix `Query` and `Form` extractors giving bad request error when query string is empty. ([#117](https://github.com/tokio-rs/axum/pull/117))
|
- Fix `Query` and `Form` extractors giving bad request error when query string is empty. ([#117](https://github.com/tokio-rs/axum/pull/117))
|
||||||
- Add `Path` extractor. ([#124](https://github.com/tokio-rs/axum/pull/124))
|
- Add `Path` extractor. ([#124](https://github.com/tokio-rs/axum/pull/124))
|
||||||
|
- Fixed the implementation of `IntoResponse` of `(HeaderMap, T)` and `(StatusCode, HeaderMap, T)` would ignore headers from `T` ([#137](https://github.com/tokio-rs/axum/pull/137))
|
||||||
|
|
||||||
## Breaking changes
|
## Breaking changes
|
||||||
|
|
||||||
|
|||||||
+41
-2
@@ -158,7 +158,7 @@ where
|
|||||||
{
|
{
|
||||||
fn into_response(self) -> Response<Body> {
|
fn into_response(self) -> Response<Body> {
|
||||||
let mut res = self.1.into_response();
|
let mut res = self.1.into_response();
|
||||||
*res.headers_mut() = self.0;
|
res.headers_mut().extend(self.0);
|
||||||
res
|
res
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -170,7 +170,7 @@ where
|
|||||||
fn into_response(self) -> Response<Body> {
|
fn into_response(self) -> Response<Body> {
|
||||||
let mut res = self.2.into_response();
|
let mut res = self.2.into_response();
|
||||||
*res.status_mut() = self.0;
|
*res.status_mut() = self.0;
|
||||||
*res.headers_mut() = self.1;
|
res.headers_mut().extend(self.1);
|
||||||
res
|
res
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -264,3 +264,42 @@ impl<T> From<T> for Json<T> {
|
|||||||
Self(inner)
|
Self(inner)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use super::*;
|
||||||
|
use http::header::{HeaderMap, HeaderName};
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_merge_headers() {
|
||||||
|
struct MyResponse;
|
||||||
|
|
||||||
|
impl IntoResponse for MyResponse {
|
||||||
|
fn into_response(self) -> Response<Body> {
|
||||||
|
let mut resp = Response::new(String::new().into());
|
||||||
|
resp.headers_mut()
|
||||||
|
.insert(HeaderName::from_static("a"), HeaderValue::from_static("1"));
|
||||||
|
resp
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn check(resp: impl IntoResponse) {
|
||||||
|
let resp = resp.into_response();
|
||||||
|
assert_eq!(
|
||||||
|
resp.headers().get(HeaderName::from_static("a")).unwrap(),
|
||||||
|
&HeaderValue::from_static("1")
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
resp.headers().get(HeaderName::from_static("b")).unwrap(),
|
||||||
|
&HeaderValue::from_static("2")
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
let headers: HeaderMap =
|
||||||
|
std::iter::once((HeaderName::from_static("b"), HeaderValue::from_static("2")))
|
||||||
|
.collect();
|
||||||
|
|
||||||
|
check((headers.clone(), MyResponse));
|
||||||
|
check((StatusCode::OK, headers, MyResponse));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user