Improve spec conformance around request header validation (#33418)

* fix: improve spec conformance around request header validation

Signed-off-by: Shane Handley <shanehandley@fastmail.com>

* account for additional test passes

Signed-off-by: Shane Handley <shanehandley@fastmail.com>

* fix: remove redundant .to_vec call

Signed-off-by: Shane Handley <shanehandley@fastmail.com>

---------

Signed-off-by: Shane Handley <shanehandley@fastmail.com>
This commit is contained in:
shanehandley 2024-09-14 13:01:22 +10:00 committed by GitHub
parent 6071b4a961
commit 6a3cdc47ec
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 263 additions and 482 deletions

View file

@ -13,6 +13,7 @@ use http::method::InvalidMethod;
use http::Method as HttpMethod;
use js::jsapi::JSObject;
use js::rust::HandleObject;
use net_traits::fetch::headers::is_forbidden_method;
use net_traits::request::{
CacheMode as NetTraitsRequestCache, CredentialsMode as NetTraitsRequestCredentials,
Destination as NetTraitsRequestDestination, Origin, RedirectMode as NetTraitsRequestRedirect,
@ -503,14 +504,6 @@ fn is_method(m: &ByteString) -> bool {
m.as_str().is_some()
}
// https://fetch.spec.whatwg.org/#forbidden-method
fn is_forbidden_method(m: &ByteString) -> bool {
matches!(
m.to_lower().as_str(),
Some("connect") | Some("trace") | Some("track")
)
}
// https://fetch.spec.whatwg.org/#cors-safelisted-method
fn is_cors_safelisted_method(m: &HttpMethod) -> bool {
m == HttpMethod::GET || m == HttpMethod::HEAD || m == HttpMethod::POST