Skip to content

Commit

Permalink
Allow Request's Headers to be created with various objects
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
jeenalee committed Oct 17, 2016
1 parent f4cb87a commit 94ea24e
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 14 deletions.
38 changes: 27 additions & 11 deletions components/script/dom/request.rs
Expand Up @@ -308,21 +308,26 @@ 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();
// When r.Headers()'s header list is emptied,
// r.Headers that was filled in Step 28 becomes empty.

// Step 30
if r.request.borrow().mode == NetTraitsRequestMode::NoCORS {
Expand All @@ -341,7 +346,19 @@ impl Request {
}

// Step 31
try!(r.Headers().fill(Some(HeadersInit::Headers(headers_copy))));
if let Some(HeadersInit::Headers(_)) = init.headers {
try!(r.Headers().fill(Some(HeadersInit::Headers(headers_copy))));
};

// 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 None = init.headers {
if let RequestInfo::Request(ref input_request) = input {
try!(r.Headers().fill(Some(HeadersInit::Headers(input_request.Headers()))));
}
};

// Step 32
let mut input_body = if let RequestInfo::Request(ref input_request) = input {
Expand All @@ -368,7 +385,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();
Expand Down
3 changes: 0 additions & 3 deletions tests/wpt/metadata/fetch/api/request/request-headers.html.ini
@@ -1,8 +1,5 @@
[request-headers.html]
type: testharness
[Testing request header creations with various objects]
expected: FAIL

[Testing empty Request Content-Type header]
expected: FAIL

0 comments on commit 94ea24e

Please sign in to comment.