aboutsummaryrefslogtreecommitdiffstats
path: root/components/script/dom/request.rs
diff options
context:
space:
mode:
authorbors-servo <lbergstrom+bors@mozilla.com>2016-11-09 15:04:10 -0600
committerGitHub <noreply@github.com>2016-11-09 15:04:10 -0600
commit9a7559fd826f53a0020e5e9a575c8265ad349af7 (patch)
tree21ceaf73624a87f0251b4d3bef057975d493c160 /components/script/dom/request.rs
parent289a289da209886f7259c71f279eb11f1c8ba0a3 (diff)
parentbfd999f71e198cffb7b1e84d1848c871937e3bd8 (diff)
downloadservo-9a7559fd826f53a0020e5e9a575c8265ad349af7.tar.gz
servo-9a7559fd826f53a0020e5e9a575c8265ad349af7.zip
Auto merge of #13802 - jeenalee:request-headers, r=jdm
Allow Request's Headers to be created with various objects <!-- Please describe your changes on the following line: --> While Headers could be constructed correctly with an array or object (open ended dictionary/MozMap), Request's Headers failed to be created with non-Headers object (such as array or open ended dictionary/MozMap). Before, Request's Headers could be filled with only a Headers object in Step 28. This has been expanded to accommodate array and open ended dictionary. Step 29 empties the Request's Headers list after it had been filled in Step 28, thus resulting in an empty Headers object when it shouldn't be. This step has been removed with a comment in this commit. If a RequestInit Headers is _not_ given, but a RequestInfo Headers is given, RequestInfo Headers should be used to construct Request Headers. That step has been added after Step 31. Corresponding wpt result is updated in this commit. --- <!-- 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 #13758 (github issue number if applicable). <!-- Either: --> - [X] There are tests for these changes OR - [ ] These changes do not require tests because _____ <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. --> <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/13802) <!-- Reviewable:end -->
Diffstat (limited to 'components/script/dom/request.rs')
-rw-r--r--components/script/dom/request.rs43
1 files changed, 32 insertions, 11 deletions
diff --git a/components/script/dom/request.rs b/components/script/dom/request.rs
index e9cee6da938..fa649702259 100644
--- a/components/script/dom/request.rs
+++ b/components/script/dom/request.rs
@@ -308,21 +308,31 @@ impl Request {
// Step 27
let mut headers_copy = r.Headers();
- // This is equivalent to the specification's concept of
- // "associated headers list".
- if let RequestInfo::Request(ref input_request) = input {
- headers_copy = input_request.Headers();
- }
-
// Step 28
if let Some(possible_header) = init.headers.as_ref() {
- if let &HeadersInit::Headers(ref init_headers) = possible_header {
- headers_copy = init_headers.clone();
+ match possible_header {
+ &HeadersInit::Headers(ref init_headers) => {
+ headers_copy = init_headers.clone();
+ }
+ &HeadersInit::ByteStringSequenceSequence(ref init_sequence) => {
+ try!(headers_copy.fill(Some(
+ HeadersInit::ByteStringSequenceSequence(init_sequence.clone()))));
+ },
+ &HeadersInit::ByteStringMozMap(ref init_map) => {
+ try!(headers_copy.fill(Some(
+ HeadersInit::ByteStringMozMap(init_map.clone()))));
+ },
}
}
// Step 29
- r.Headers().empty_header_list();
+ // We cannot empty `r.Headers().header_list` because
+ // we would undo the Step 27 above. One alternative is to set
+ // `headers_copy` as a deep copy of `r.Headers()`. However,
+ // `r.Headers()` is a `Root<T>`, and therefore it is difficult
+ // to obtain a mutable reference to `r.Headers()`. Without the
+ // mutable reference, we cannot mutate `r.Headers()` to be the
+ // deep copied headers in Step 27.
// Step 30
if r.request.borrow().mode == NetTraitsRequestMode::NoCORS {
@@ -341,7 +351,19 @@ impl Request {
}
// Step 31
- try!(r.Headers().fill(Some(HeadersInit::Headers(headers_copy))));
+ match init.headers {
+ None => {
+ // This is equivalent to the specification's concept of
+ // "associated headers list". If an init headers is not given,
+ // but an input with headers is given, set request's
+ // headers as the input's Headers.
+ if let RequestInfo::Request(ref input_request) = input {
+ try!(r.Headers().fill(Some(HeadersInit::Headers(input_request.Headers()))));
+ }
+ },
+ Some(HeadersInit::Headers(_)) => try!(r.Headers().fill(Some(HeadersInit::Headers(headers_copy)))),
+ _ => {},
+ }
// Step 32
let mut input_body = if let RequestInfo::Request(ref input_request) = input {
@@ -368,7 +390,6 @@ impl Request {
}
// Step 34
- // TODO: `ReadableStream` object is not implemented in Servo yet.
if let Some(Some(ref init_body)) = init.body {
// Step 34.2
let extracted_body_tmp = init_body.extract();