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:
bors-servo 2017-01-09 18:36:38 -08:00 committed by GitHub
commit f1c82be0e6
23 changed files with 45 additions and 259 deletions

View file

@ -172,8 +172,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()))
}
}