mirror of
https://github.com/actix/actix-web.git
synced 2025-03-05 11:01:13 +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.
|
- 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`.
|
- Update `brotli` dependency to `7`.
|
||||||
- Minimum supported Rust version (MSRV) is now 1.75.
|
- 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
|
## 4.9.0
|
||||||
|
|
||||||
|
|
|
@ -66,6 +66,7 @@ fn get_host_uri(req: &RequestHead) -> Option<Uri> {
|
||||||
req.headers
|
req.headers
|
||||||
.get(header::HOST)
|
.get(header::HOST)
|
||||||
.and_then(|host_value| host_value.to_str().ok())
|
.and_then(|host_value| host_value.to_str().ok())
|
||||||
|
.filter(|_| req.version < actix_http::Version::HTTP_2)
|
||||||
.or_else(|| req.uri.host())
|
.or_else(|| req.uri.host())
|
||||||
.and_then(|host| host.parse().ok())
|
.and_then(|host| host.parse().ok())
|
||||||
}
|
}
|
||||||
|
@ -123,6 +124,38 @@ mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
use crate::test::TestRequest;
|
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]
|
#[test]
|
||||||
fn host_from_header() {
|
fn host_from_header() {
|
||||||
let req = TestRequest::default()
|
let req = TestRequest::default()
|
||||||
|
|
Loading…
Reference in a new issue