Auto merge of #29236 - servo:application-json, r=jdm

Allow displaying content with "application/json" mime type

For me this allows the WPT test
performance-timeline/tentative/include-frames-one-remote-child.sub.html
to match expected results. The wptserver is sending a 404 JSON response
because the URL that the test requests is not found.

<!-- Please describe your changes on the following line: -->

---
<!-- 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 #29136.
- [x] There are tests for these changes.

<!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.-->

<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->
This commit is contained in:
bors-servo 2023-01-17 19:13:38 +01:00 committed by GitHub
commit a8db596d1e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 26 additions and 34 deletions

View file

@ -829,13 +829,24 @@ impl FetchResponseListener for ParserContext {
}
parser.document.set_csp_list(csp_list);
self.parser = Some(Trusted::new(&*parser));
self.submit_resource_timing();
match content_type {
Some(ref mime) if mime.type_() == mime::IMAGE => {
let content_type = match content_type {
Some(ref content_type) => content_type,
None => {
// No content-type header.
// Merge with #4212 when fixed.
return;
},
};
match (
content_type.type_(),
content_type.subtype(),
content_type.suffix(),
) {
(mime::IMAGE, _, _) => {
self.is_synthesized_document = true;
let page = "<html><body></body></html>".into();
parser.push_string_input_chunk(page);
@ -849,15 +860,14 @@ impl FetchResponseListener for ParserContext {
.AppendChild(&DomRoot::upcast::<Node>(img))
.expect("Appending failed");
},
Some(ref mime) if mime.type_() == mime::TEXT && mime.subtype() == mime::PLAIN => {
(mime::TEXT, mime::PLAIN, _) => {
// https://html.spec.whatwg.org/multipage/#read-text
let page = "<pre>\n".into();
parser.push_string_input_chunk(page);
parser.parse_sync();
parser.tokenizer.borrow_mut().set_plaintext_state();
},
Some(ref mime) if mime.type_() == mime::TEXT && mime.subtype() == mime::HTML => {
// Handle text/html
(mime::TEXT, mime::HTML, _) => {
if let Some((reason, bytes)) = ssl_error {
self.is_synthesized_document = true;
let page = resources::read_string(Resource::BadCertHTML);
@ -877,29 +887,21 @@ impl FetchResponseListener for ParserContext {
parser.parse_sync();
}
},
// Handle text/xml, application/xml
Some(ref mime)
if (mime.type_() == mime::TEXT && mime.subtype() == mime::XML) ||
(mime.type_() == mime::APPLICATION && mime.subtype() == mime::XML) => {},
Some(ref mime)
if mime.type_() == mime::APPLICATION &&
mime.subtype().as_str() == "xhtml" &&
mime.suffix() == Some(mime::XML) => {}, // Handle xhtml (application/xhtml+xml)
Some(ref mime) => {
(mime::TEXT, mime::XML, _) |
(mime::APPLICATION, mime::XML, _) |
(mime::APPLICATION, mime::JSON, _) => {},
(mime::APPLICATION, subtype, Some(mime::XML)) if subtype == "xhtml" => {},
(mime_type, subtype, _) => {
// Show warning page for unknown mime types.
let page = format!(
"<html><body><p>Unknown content type ({}/{}).</p></body></html>",
mime.type_().as_str(),
mime.subtype().as_str()
mime_type.as_str(),
subtype.as_str()
);
self.is_synthesized_document = true;
parser.push_string_input_chunk(page);
parser.parse_sync();
},
None => {
// No content-type header.
// Merge with #4212 when fixed.
},
}
}