Auto merge of #26442 - Eijebong:might-have-failed-going-to-bed, r=jdm

Fix the webidl for Headers

Make the HeadersInit type match the spec.

Fixes #26441
This commit is contained in:
bors-servo 2020-05-30 08:14:53 -04:00 committed by GitHub
commit dafcee4c2e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 28 additions and 55 deletions

View file

@ -198,20 +198,19 @@ impl HeadersMethods for Headers {
} }
impl Headers { impl Headers {
// https://fetch.spec.whatwg.org/#concept-headers-fill pub fn copy_from_headers(&self, headers: DomRoot<Headers>) -> ErrorResult {
pub fn fill(&self, filler: Option<HeadersInit>) -> ErrorResult { for (name, value) in headers.header_list.borrow().iter() {
match filler {
// Step 1
Some(HeadersInit::Headers(h)) => {
for (name, value) in h.header_list.borrow().iter() {
self.Append( self.Append(
ByteString::new(Vec::from(name.as_str())), ByteString::new(Vec::from(name.as_str())),
ByteString::new(Vec::from(value.as_bytes())), ByteString::new(Vec::from(value.as_bytes())),
)?; )?;
} }
Ok(()) Ok(())
}, }
// Step 2
// https://fetch.spec.whatwg.org/#concept-headers-fill
pub fn fill(&self, filler: Option<HeadersInit>) -> ErrorResult {
match filler {
Some(HeadersInit::ByteStringSequenceSequence(v)) => { Some(HeadersInit::ByteStringSequenceSequence(v)) => {
for mut seq in v { for mut seq in v {
if seq.len() == 2 { if seq.len() == 2 {

View file

@ -311,27 +311,17 @@ impl Request {
r.headers.or_init(|| Headers::for_request(&r.global())); r.headers.or_init(|| Headers::for_request(&r.global()));
// Step 32 - but spec says this should only be when non-empty init? // Step 32 - but spec says this should only be when non-empty init?
// Step 32.1 let headers_copy = init
let mut headers_copy = r.Headers(); .headers
.as_ref()
// Step 32.2 .map(|possible_header| match possible_header {
if let Some(possible_header) = init.headers.as_ref() { HeadersInit::ByteStringSequenceSequence(init_sequence) => {
match possible_header { HeadersInit::ByteStringSequenceSequence(init_sequence.clone())
&HeadersInit::Headers(ref init_headers) => {
headers_copy = DomRoot::from_ref(&*init_headers);
}, },
&HeadersInit::ByteStringSequenceSequence(ref init_sequence) => { HeadersInit::ByteStringByteStringRecord(init_map) => {
headers_copy.fill(Some(HeadersInit::ByteStringSequenceSequence( HeadersInit::ByteStringByteStringRecord(init_map.clone())
init_sequence.clone(),
)))?;
}, },
&HeadersInit::ByteStringByteStringRecord(ref init_map) => { });
headers_copy.fill(Some(HeadersInit::ByteStringByteStringRecord(
init_map.clone(),
)))?;
},
}
}
// Step 32.3 // Step 32.3
// We cannot empty `r.Headers().header_list` because // We cannot empty `r.Headers().header_list` because
@ -357,21 +347,17 @@ impl Request {
} }
// Step 32.5 // Step 32.5
match init.headers { match headers_copy {
None => { None => {
// This is equivalent to the specification's concept of // This is equivalent to the specification's concept of
// "associated headers list". If an init headers is not given, // "associated headers list". If an init headers is not given,
// but an input with headers is given, set request's // but an input with headers is given, set request's
// headers as the input's Headers. // headers as the input's Headers.
if let RequestInfo::Request(ref input_request) = input { if let RequestInfo::Request(ref input_request) = input {
r.Headers() r.Headers().copy_from_headers(input_request.Headers())?;
.fill(Some(HeadersInit::Headers(input_request.Headers())))?;
} }
}, },
Some(HeadersInit::Headers(_)) => { Some(headers_copy) => r.Headers().fill(Some(headers_copy))?,
r.Headers().fill(Some(HeadersInit::Headers(headers_copy)))?
},
_ => {},
} }
// Step 32.5-6 depending on how we got here // Step 32.5-6 depending on how we got here
@ -493,9 +479,7 @@ impl Request {
*r_clone.request.borrow_mut() = req.clone(); *r_clone.request.borrow_mut() = req.clone();
r_clone.body_used.set(body_used); r_clone.body_used.set(body_used);
*r_clone.mime_type.borrow_mut() = mime_type; *r_clone.mime_type.borrow_mut() = mime_type;
r_clone r_clone.Headers().copy_from_headers(r.Headers())?;
.Headers()
.fill(Some(HeadersInit::Headers(r.Headers())))?;
r_clone.Headers().set_guard(headers_guard); r_clone.Headers().set_guard(headers_guard);
Ok(r_clone) Ok(r_clone)
} }
@ -895,7 +879,6 @@ impl Into<RequestRedirect> for NetTraitsRequestRedirect {
impl Clone for HeadersInit { impl Clone for HeadersInit {
fn clone(&self) -> HeadersInit { fn clone(&self) -> HeadersInit {
match self { match self {
&HeadersInit::Headers(ref h) => HeadersInit::Headers(h.clone()),
&HeadersInit::ByteStringSequenceSequence(ref b) => { &HeadersInit::ByteStringSequenceSequence(ref b) => {
HeadersInit::ByteStringSequenceSequence(b.clone()) HeadersInit::ByteStringSequenceSequence(b.clone())
}, },

View file

@ -4,7 +4,7 @@
use crate::body::{consume_body, consume_body_with_promise, BodyOperations, BodyType}; use crate::body::{consume_body, consume_body_with_promise, BodyOperations, BodyType};
use crate::dom::bindings::cell::{DomRefCell, Ref}; use crate::dom::bindings::cell::{DomRefCell, Ref};
use crate::dom::bindings::codegen::Bindings::HeadersBinding::{HeadersInit, HeadersMethods}; use crate::dom::bindings::codegen::Bindings::HeadersBinding::HeadersMethods;
use crate::dom::bindings::codegen::Bindings::ResponseBinding; use crate::dom::bindings::codegen::Bindings::ResponseBinding;
use crate::dom::bindings::codegen::Bindings::ResponseBinding::{ use crate::dom::bindings::codegen::Bindings::ResponseBinding::{
ResponseMethods, ResponseType as DOMResponseType, ResponseMethods, ResponseType as DOMResponseType,
@ -335,9 +335,7 @@ impl ResponseMethods for Response {
// Step 2 // Step 2
let new_response = Response::new(&self.global()); let new_response = Response::new(&self.global());
new_response.Headers().set_guard(self.Headers().get_guard()); new_response.Headers().set_guard(self.Headers().get_guard());
new_response new_response.Headers().copy_from_headers(self.Headers())?;
.Headers()
.fill(Some(HeadersInit::Headers(self.Headers())))?;
// https://fetch.spec.whatwg.org/#concept-response-clone // https://fetch.spec.whatwg.org/#concept-response-clone
// Instead of storing a net_traits::Response internally, we // Instead of storing a net_traits::Response internally, we

View file

@ -4,7 +4,7 @@
// https://fetch.spec.whatwg.org/#headers-class // https://fetch.spec.whatwg.org/#headers-class
typedef (Headers or sequence<sequence<ByteString>> or record<ByteString, ByteString>) HeadersInit; typedef (sequence<sequence<ByteString>> or record<ByteString, ByteString>) HeadersInit;
[Exposed=(Window,Worker)] [Exposed=(Window,Worker)]
interface Headers { interface Headers {

View file

@ -1,5 +0,0 @@
[headers-basic.html]
type: testharness
[Create headers with existing headers with custom iterator]
expected: FAIL

View file

@ -5,11 +5,10 @@
[general] [general]
expected: FAIL expected: FAIL
[Privileged header not allowed for guard type: request-no-cors]
expected: FAIL
[Fetch with range header will be sent with Accept-Encoding: identity] [Fetch with range header will be sent with Accept-Encoding: identity]
expected: FAIL expected: FAIL
[general.any.html] [general.any.html]
[Untitled] [Untitled]
expected: FAIL expected: FAIL
@ -17,7 +16,6 @@
[general] [general]
expected: FAIL expected: FAIL
[Privileged header not allowed for guard type: request-no-cors]
expected: FAIL
[Fetch with range header will be sent with Accept-Encoding: identity] [Fetch with range header will be sent with Accept-Encoding: identity]
expected: FAIL expected: FAIL