diff options
-rw-r--r-- | components/script/dom/request.rs | 22 | ||||
-rw-r--r-- | tests/wpt/metadata/fetch/api/basic/request-headers.any.js.ini | 31 |
2 files changed, 18 insertions, 35 deletions
diff --git a/components/script/dom/request.rs b/components/script/dom/request.rs index 03e5dee683d..29fd8a15c18 100644 --- a/components/script/dom/request.rs +++ b/components/script/dom/request.rs @@ -25,6 +25,7 @@ use crate::dom::headers::{Guard, Headers}; use crate::dom::promise::Promise; use crate::dom::xmlhttprequest::Extractable; use dom_struct::dom_struct; +use http::header::{HeaderName, HeaderValue}; use http::method::InvalidMethod; use http::Method as HttpMethod; use net_traits::request::CacheMode as NetTraitsRequestCache; @@ -309,7 +310,8 @@ impl Request { // Step 30 TODO: "If signal is not null..." // Step 31 - // "or_init" looks unclear here + // "or_init" looks unclear here, but it always enters the block since r + // hasn't had any other way to initialize its headers r.headers.or_init(|| Headers::for_request(&r.global())); // Step 32 - but spec says this should only be when non-empty init? @@ -420,15 +422,27 @@ impl Request { // Step 36.4 if let Some(contents) = content_type { + let ct_header_name = b"Content-Type"; if !r .Headers() - .Has(ByteString::new(b"Content-Type".to_vec())) + .Has(ByteString::new(ct_header_name.to_vec())) .unwrap() { + let ct_header_val = contents.as_bytes(); r.Headers().Append( - ByteString::new(b"Content-Type".to_vec()), - ByteString::new(contents.as_bytes().to_vec()), + ByteString::new(ct_header_name.to_vec()), + ByteString::new(ct_header_val.to_vec()), )?; + + // In Servo r.Headers's header list isn't a pointer to + // the same actual list as r.request's, and so we need to + // append to both lists to keep them in sync. + if let Ok(v) = HeaderValue::from_bytes(ct_header_val) { + r.request + .borrow_mut() + .headers + .insert(HeaderName::from_bytes(ct_header_name).unwrap(), v); + } } } } diff --git a/tests/wpt/metadata/fetch/api/basic/request-headers.any.js.ini b/tests/wpt/metadata/fetch/api/basic/request-headers.any.js.ini index b60fcf744cf..34647dbc095 100644 --- a/tests/wpt/metadata/fetch/api/basic/request-headers.any.js.ini +++ b/tests/wpt/metadata/fetch/api/basic/request-headers.any.js.ini @@ -1,47 +1,16 @@ [request-headers.any.html] type: testharness - [Fetch with PUT with body] - expected: FAIL - - [Fetch with POST with text body] - expected: FAIL - [Fetch with POST with FormData body] expected: FAIL - [Fetch with POST with URLSearchParams body] - expected: FAIL - - [Fetch with POST with Blob body with mime type] - expected: FAIL - [Fetch with Chicken] expected: FAIL - [Fetch with Chicken with body] - expected: FAIL - - [request-headers.any.worker.html] type: testharness - [Fetch with PUT with body] - expected: FAIL - - [Fetch with POST with text body] - expected: FAIL - [Fetch with POST with FormData body] expected: FAIL - [Fetch with POST with URLSearchParams body] - expected: FAIL - - [Fetch with POST with Blob body with mime type] - expected: FAIL - [Fetch with Chicken] expected: FAIL - [Fetch with Chicken with body] - expected: FAIL - |