mirror of
https://github.com/servo/servo.git
synced 2025-08-03 20:50:07 +01:00
Auto merge of #14868 - bd339:iss14068, r=jdm
Fix loss of response type information in Fetch API <!-- Please describe your changes on the following line: --> Avoids mapping response types that are distinct according to [the spec](https://fetch.spec.whatwg.org/#concept-response-type) to fewer response types. Also updates test expectations to match that we now pass tests that check the response type. --- <!-- 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 #14068 <!-- Either: --> - [X] There are tests for these changes <!-- 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/14868) <!-- Reviewable:end -->
This commit is contained in:
commit
f1c82be0e6
23 changed files with 45 additions and 259 deletions
|
@ -172,8 +172,10 @@ pub trait FetchTaskTarget {
|
|||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
pub enum FilteredMetadata {
|
||||
Basic(Metadata),
|
||||
Cors(Metadata),
|
||||
Opaque,
|
||||
Transparent(Metadata),
|
||||
OpaqueRedirect
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
|
|
|
@ -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()))
|
||||
}
|
||||
}
|
||||
|
|
|
@ -854,8 +854,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(_) => {
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
@ -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
|
||||
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -1,5 +0,0 @@
|
|||
[referrer-no-referrer-worker.html]
|
||||
type: testharness
|
||||
[Request's referrer is empty]
|
||||
expected: FAIL
|
||||
|
|
@ -1,5 +0,0 @@
|
|||
[referrer-no-referrer.html]
|
||||
type: testharness
|
||||
[Request's referrer is empty]
|
||||
expected: FAIL
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue