mirror of
https://github.com/actix/actix-web.git
synced 2024-12-16 21:26:34 +00:00
feat(guard): do not use host header on http2 for guard
This commit is contained in:
parent
8115c818c1
commit
228fd81e96
2 changed files with 34 additions and 0 deletions
|
@ -5,6 +5,7 @@
|
|||
- On Windows, an error is now returned from `HttpServer::bind()` (or TLS variants) when binding to a socket that's already in use.
|
||||
- Update `brotli` dependency to `7`.
|
||||
- Minimum supported Rust version (MSRV) is now 1.75.
|
||||
- Guard Host does not use Host header anymore when on HTTP/2, it only use authority pseudo header.
|
||||
|
||||
## 4.9.0
|
||||
|
||||
|
|
|
@ -66,6 +66,7 @@ fn get_host_uri(req: &RequestHead) -> Option<Uri> {
|
|||
req.headers
|
||||
.get(header::HOST)
|
||||
.and_then(|host_value| host_value.to_str().ok())
|
||||
.filter(|_| req.version < actix_http::Version::HTTP_2)
|
||||
.or_else(|| req.uri.host())
|
||||
.and_then(|host| host.parse().ok())
|
||||
}
|
||||
|
@ -123,6 +124,38 @@ mod tests {
|
|||
use super::*;
|
||||
use crate::test::TestRequest;
|
||||
|
||||
#[test]
|
||||
fn host_not_from_header_if_http2() {
|
||||
let req = TestRequest::default()
|
||||
.uri("www.rust-lang.org")
|
||||
.insert_header((
|
||||
header::HOST,
|
||||
header::HeaderValue::from_static("www.example.com"),
|
||||
))
|
||||
.to_srv_request();
|
||||
|
||||
let host = Host("www.example.com");
|
||||
assert!(host.check(&req.guard_ctx()));
|
||||
|
||||
let host = Host("www.rust-lang.org");
|
||||
assert!(!host.check(&req.guard_ctx()));
|
||||
|
||||
let req = TestRequest::default()
|
||||
.version(actix_http::Version::HTTP_2)
|
||||
.uri("www.rust-lang.org")
|
||||
.insert_header((
|
||||
header::HOST,
|
||||
header::HeaderValue::from_static("www.example.com"),
|
||||
))
|
||||
.to_srv_request();
|
||||
|
||||
let host = Host("www.example.com");
|
||||
assert!(!host.check(&req.guard_ctx()));
|
||||
|
||||
let host = Host("www.rust-lang.org");
|
||||
assert!(host.check(&req.guard_ctx()));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn host_from_header() {
|
||||
let req = TestRequest::default()
|
||||
|
|
Loading…
Reference in a new issue