aboutsummaryrefslogtreecommitdiffstats
path: root/components/script/dom
diff options
context:
space:
mode:
authorbors-servo <lbergstrom+bors@mozilla.com>2019-12-22 11:12:56 -0500
committerGitHub <noreply@github.com>2019-12-22 11:12:56 -0500
commit43a5f65940f85a30ba3f7fb9cbb96b194cde81b6 (patch)
tree841a9afe8ebd27e56c6f83df044f1ebb1629b7a2 /components/script/dom
parent3e77a0ae09daf28c0a102add5a198bff08befe31 (diff)
parentb9c4b64978dcd1b4e767f8ca6ed07a06902c4c5b (diff)
downloadservo-43a5f65940f85a30ba3f7fb9cbb96b194cde81b6.tar.gz
servo-43a5f65940f85a30ba3f7fb9cbb96b194cde81b6.zip
Auto merge of #25359 - pshaughn:auto_ct_header, r=jdm
Autocomputed content-type header now reaches net request The spec expects that for a DOM Request r, r.headers and r.request can actually refer to the same header list in RAM, with changes to one affecting the other. This is mostly unobservable, but it happens to come up at the point in the Request constructor that auto-infers a content type from the body, so now after inferring the content type it injects it into both header lists instead of one. Remaining test failures are due to the way Hyper crates normalize semicolons in MIME types, and an actually separate problem about content-lengths that I haven't sniffed out yet. --- <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `___` with appropriate data: --> - [X] `./mach build -d` does not report any errors - [X] `./mach test-tidy` does not report any errors - [X] These changes fix some WPT results from #24904 <!-- Either: --> - [X] There are tests for these changes <!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.--> <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->
Diffstat (limited to 'components/script/dom')
-rw-r--r--components/script/dom/request.rs22
1 files changed, 18 insertions, 4 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);
+ }
}
}
}