Don't lose information in Fetch API

Also update test expectations.
This commit is contained in:
bd339 2017-01-05 01:00:03 +01:00
parent f838944332
commit 0f1eb13e33
23 changed files with 45 additions and 259 deletions

View file

@ -173,8 +173,10 @@ pub trait FetchTaskTarget {
#[derive(Serialize, Deserialize)]
pub enum FilteredMetadata {
Basic(Metadata),
Cors(Metadata),
Opaque,
Transparent(Metadata),
OpaqueRedirect
}
#[derive(Serialize, Deserialize)]

View file

@ -270,17 +270,32 @@ impl Response {
Some(ref url) => {
let unsafe_metadata = init_metadata(response, url);
Ok(FetchMetadata::Filtered {
filtered: match metadata {
Some(m) => FilteredMetadata::Transparent(m),
None => FilteredMetadata::Opaque,
},
unsafe_: unsafe_metadata,
match self.response_type {
ResponseType::Basic => Ok(FetchMetadata::Filtered {
filtered: FilteredMetadata::Basic(metadata.unwrap()),
unsafe_: unsafe_metadata
}),
ResponseType::Cors => Ok(FetchMetadata::Filtered {
filtered: FilteredMetadata::Cors(metadata.unwrap()),
unsafe_: unsafe_metadata
}),
ResponseType::Default => unreachable!(),
ResponseType::Error(ref network_err) =>
Err(network_err.clone()),
ResponseType::Opaque => Ok(FetchMetadata::Filtered {
filtered: FilteredMetadata::Opaque,
unsafe_: unsafe_metadata
}),
ResponseType::OpaqueRedirect => Ok(FetchMetadata::Filtered {
filtered: FilteredMetadata::OpaqueRedirect,
unsafe_: unsafe_metadata
})
}
},
None => Err(NetworkError::Internal("No url found in unsafe response".to_owned())),
None => Err(NetworkError::Internal("No url found in unsafe response".to_owned()))
}
} else {
assert_eq!(self.response_type, ResponseType::Default);
Ok(FetchMetadata::Unfiltered(metadata.unwrap()))
}
}

View file

@ -835,8 +835,10 @@ impl XMLHttpRequest {
Ok(meta) => match meta {
FetchMetadata::Unfiltered(m) => m,
FetchMetadata::Filtered { filtered, .. } => match filtered {
FilteredMetadata::Basic(m) => m,
FilteredMetadata::Cors(m) => m,
FilteredMetadata::Opaque => return Err(Error::Network),
FilteredMetadata::Transparent(m) => m
FilteredMetadata::OpaqueRedirect => return Err(Error::Network)
}
},
Err(_) => {

View file

@ -135,18 +135,29 @@ impl FetchResponseListener for FetchContext {
promise.global().get_cx(),
Error::Type("Network error occurred".to_string()));
self.fetch_promise = Some(TrustedPromise::new(promise));
self.response_object.root().set_type(DOMResponseType::Error);
return;
},
// Step 4.2
Ok(metadata) => {
match metadata {
FetchMetadata::Unfiltered(m) =>
fill_headers_with_metadata(self.response_object.root(), m),
FetchMetadata::Unfiltered(m) => {
fill_headers_with_metadata(self.response_object.root(), m);
self.response_object.root().set_type(DOMResponseType::Default);
},
FetchMetadata::Filtered { filtered, .. } => match filtered {
FilteredMetadata::Transparent(m) =>
fill_headers_with_metadata(self.response_object.root(), m),
FilteredMetadata::Basic(m) => {
fill_headers_with_metadata(self.response_object.root(), m);
self.response_object.root().set_type(DOMResponseType::Basic);
},
FilteredMetadata::Cors(m) => {
fill_headers_with_metadata(self.response_object.root(), m);
self.response_object.root().set_type(DOMResponseType::Cors);
},
FilteredMetadata::Opaque =>
self.response_object.root().set_type(DOMResponseType::Opaque),
FilteredMetadata::OpaqueRedirect =>
self.response_object.root().set_type(DOMResponseType::Opaqueredirect)
}
}
}

View file

@ -32,7 +32,7 @@ fn assert_parse(url: &'static str,
assert_eq!(header_content_type, content_type.as_ref());
let metadata = match response.metadata() {
Ok(FetchMetadata::Filtered { filtered: FilteredMetadata::Transparent(m), .. }) => m,
Ok(FetchMetadata::Filtered { filtered: FilteredMetadata::Basic(m), .. }) => m,
result => panic!(result),
};
assert_eq!(metadata.content_type.map(Serde::into_inner), content_type);

View file

@ -1,14 +1,8 @@
[accept-header-worker.html]
type: testharness
[Request through fetch should have 'accept' header with value '*/*']
expected: FAIL
[Request through fetch should have 'accept' header with value 'custom/*']
expected: FAIL
[Request through fetch should have a 'accept-language' header]
expected: FAIL
[Request through fetch should have 'accept-language' header with value 'bzh']
expected: FAIL

View file

@ -1,14 +1,8 @@
[accept-header.html]
type: testharness
[Request through fetch should have 'accept' header with value '*/*']
expected: FAIL
[Request through fetch should have 'accept' header with value 'custom/*']
expected: FAIL
[Request through fetch should have a 'accept-language' header]
expected: FAIL
[Request through fetch should have 'accept-language' header with value 'bzh']
expected: FAIL

View file

@ -1,11 +1,5 @@
[mode-no-cors-worker.html]
type: testharness
[Fetch ../resources/top.txt with no-cors mode]
expected: FAIL
[Fetch http://web-platform.test:8000/fetch/api/resources/top.txt with no-cors mode]
expected: FAIL
[Fetch https://web-platform.test:8443/fetch/api/resources/top.txt with no-cors mode]
expected: FAIL

View file

@ -1,11 +1,5 @@
[mode-no-cors.html]
type: testharness
[Fetch ../resources/top.txt with no-cors mode]
expected: FAIL
[Fetch http://web-platform.test:8000/fetch/api/resources/top.txt with no-cors mode]
expected: FAIL
[Fetch https://web-platform.test:8443/fetch/api/resources/top.txt with no-cors mode]
expected: FAIL

View file

@ -1,17 +1,5 @@
[mode-same-origin-worker.html]
type: testharness
[Fetch ../resources/top.txt with same-origin mode]
expected: FAIL
[Fetch http://web-platform.test:8000/fetch/api/resources/top.txt with same-origin mode]
expected: FAIL
[Fetch http://www1.web-platform.test:8000/fetch/api/resources/top.txt with same-origin mode]
expected: FAIL
[Fetch /fetch/api/basic/../resources/redirect.py?location=../resources/top.txt with same-origin mode]
expected: FAIL
[Fetch /fetch/api/basic/../resources/redirect.py?location=http://web-platform.test:8000/fetch/api/resources/top.txt with same-origin mode]
expected: FAIL

View file

@ -1,17 +1,5 @@
[mode-same-origin.html]
type: testharness
[Fetch ../resources/top.txt with same-origin mode]
expected: FAIL
[Fetch http://web-platform.test:8000/fetch/api/resources/top.txt with same-origin mode]
expected: FAIL
[Fetch http://www1.web-platform.test:8000/fetch/api/resources/top.txt with same-origin mode]
expected: FAIL
[Fetch /fetch/api/basic/../resources/redirect.py?location=../resources/top.txt with same-origin mode]
expected: FAIL
[Fetch /fetch/api/basic/../resources/redirect.py?location=http://web-platform.test:8000/fetch/api/resources/top.txt with same-origin mode]
expected: FAIL

View file

@ -1,8 +1,5 @@
[request-forbidden-headers-worker.html]
type: testharness
[Accept-Charset is a forbidden request header]
expected: FAIL
[Accept-Encoding is a forbidden request header]
expected: FAIL
@ -12,63 +9,3 @@
[Access-Control-Request-Method is a forbidden request header]
expected: FAIL
[Connection is a forbidden request header]
expected: FAIL
[Content-Length is a forbidden request header]
expected: FAIL
[Cookie is a forbidden request header]
expected: FAIL
[Cookie2 is a forbidden request header]
expected: FAIL
[Date is a forbidden request header]
expected: FAIL
[DNT is a forbidden request header]
expected: FAIL
[Expect is a forbidden request header]
expected: FAIL
[Host is a forbidden request header]
expected: FAIL
[Keep-Alive is a forbidden request header]
expected: FAIL
[Origin is a forbidden request header]
expected: FAIL
[Referer is a forbidden request header]
expected: FAIL
[TE is a forbidden request header]
expected: FAIL
[Trailer is a forbidden request header]
expected: FAIL
[Transfer-Encoding is a forbidden request header]
expected: FAIL
[Upgrade is a forbidden request header]
expected: FAIL
[Via is a forbidden request header]
expected: FAIL
[Proxy- is a forbidden request header]
expected: FAIL
[Proxy-Test is a forbidden request header]
expected: FAIL
[Sec- is a forbidden request header]
expected: FAIL
[Sec-Test is a forbidden request header]
expected: FAIL

View file

@ -1,8 +1,5 @@
[request-forbidden-headers.html]
type: testharness
[Accept-Charset is a forbidden request header]
expected: FAIL
[Accept-Encoding is a forbidden request header]
expected: FAIL
@ -12,63 +9,3 @@
[Access-Control-Request-Method is a forbidden request header]
expected: FAIL
[Connection is a forbidden request header]
expected: FAIL
[Content-Length is a forbidden request header]
expected: FAIL
[Cookie is a forbidden request header]
expected: FAIL
[Cookie2 is a forbidden request header]
expected: FAIL
[Date is a forbidden request header]
expected: FAIL
[DNT is a forbidden request header]
expected: FAIL
[Expect is a forbidden request header]
expected: FAIL
[Host is a forbidden request header]
expected: FAIL
[Keep-Alive is a forbidden request header]
expected: FAIL
[Origin is a forbidden request header]
expected: FAIL
[Referer is a forbidden request header]
expected: FAIL
[TE is a forbidden request header]
expected: FAIL
[Trailer is a forbidden request header]
expected: FAIL
[Transfer-Encoding is a forbidden request header]
expected: FAIL
[Upgrade is a forbidden request header]
expected: FAIL
[Via is a forbidden request header]
expected: FAIL
[Proxy- is a forbidden request header]
expected: FAIL
[Proxy-Test is a forbidden request header]
expected: FAIL
[Sec- is a forbidden request header]
expected: FAIL
[Sec-Test is a forbidden request header]
expected: FAIL

View file

@ -1,11 +1,5 @@
[request-headers-worker.html]
type: testharness
[Fetch with GET]
expected: FAIL
[Fetch with HEAD]
expected: FAIL
[Fetch with PUT without body]
expected: FAIL
@ -54,9 +48,6 @@
[Fetch with POST with URLSearchParams body]
expected: FAIL
[Fetch with GET and mode "cors" does not need an Origin header]
expected: FAIL
[Fetch with POST and mode "same-origin" needs an Origin header]
expected: FAIL

View file

@ -1,11 +1,5 @@
[request-headers.html]
type: testharness
[Fetch with GET]
expected: FAIL
[Fetch with HEAD]
expected: FAIL
[Fetch with PUT without body]
expected: FAIL
@ -54,9 +48,6 @@
[Fetch with POST with URLSearchParams body]
expected: FAIL
[Fetch with GET and mode "cors" does not need an Origin header]
expected: FAIL
[Fetch with POST and mode "same-origin" needs an Origin header]
expected: FAIL

View file

@ -1,6 +0,0 @@
[scheme-blob-worker.html]
type: testharness
[Fetching [GET\] URL.createObjectURL(blob) is OK]
bug: https://github.com/servo/servo/issues/13766
expected: FAIL

View file

@ -1,6 +0,0 @@
[scheme-blob.html]
type: testharness
[Fetching [GET\] URL.createObjectURL(blob) is OK]
bug: https://github.com/servo/servo/issues/13766
expected: FAIL

View file

@ -9,12 +9,6 @@
[Fetching data:,response%27s%20body is OK (cors)]
expected: FAIL
[Fetching data:text/plain;base64,cmVzcG9uc2UncyBib[...\] is OK]
expected: FAIL
[Fetching data:image/png;base64,cmVzcG9uc2UncyBib2[...\] is OK]
expected: FAIL
[Fetching [POST\] data:,response%27s%20body is OK]
expected: FAIL

View file

@ -9,12 +9,6 @@
[Fetching data:,response%27s%20body is OK (cors)]
expected: FAIL
[Fetching data:text/plain;base64,cmVzcG9uc2UncyBib[...\] is OK]
expected: FAIL
[Fetching data:image/png;base64,cmVzcG9uc2UncyBib2[...\] is OK]
expected: FAIL
[Fetching [POST\] data:,response%27s%20body is OK]
expected: FAIL

View file

@ -1,20 +1,11 @@
[cookies-worker.html]
type: testharness
[Include mode: 1 cookie]
expected: FAIL
[Include mode: 2 cookies]
expected: FAIL
[Omit mode: discard cookies]
expected: FAIL
[Omit mode: no cookie is stored]
expected: FAIL
[Omit mode: no cookie is sent]
expected: FAIL
[Same-origin mode: 1 cookie]
expected: FAIL

View file

@ -1,20 +1,11 @@
[cookies.html]
type: testharness
[Include mode: 1 cookie]
expected: FAIL
[Include mode: 2 cookies]
expected: FAIL
[Omit mode: discard cookies]
expected: FAIL
[Omit mode: no cookie is stored]
expected: FAIL
[Omit mode: no cookie is sent]
expected: FAIL
[Same-origin mode: 1 cookie]
expected: FAIL

View file

@ -1,5 +0,0 @@
[referrer-no-referrer-worker.html]
type: testharness
[Request's referrer is empty]
expected: FAIL

View file

@ -1,5 +0,0 @@
[referrer-no-referrer.html]
type: testharness
[Request's referrer is empty]
expected: FAIL