Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set response mime_type based on Content-Type #24669

Merged
merged 1 commit into from Nov 19, 2019

Conversation

@glowe
Copy link

glowe commented Nov 6, 2019

Set the response's mime_type based on its Content-Type header whenever Response::set_headers is called. This ensures that mime_type is always consistent with Content-Type. The other reason for going with this approach is it relies on extract_mime_type:

// https://fetch.spec.whatwg.org/#concept-header-extract-mime-type
pub fn extract_mime_type(&self) -> Vec<u8> {

Besides the consistency argument, I also expect that we'll update the extract_mime_type method to conform with its specification.

Another option I explored was adding a set_mime_type member to Response and calling that with the mime type from Metadata::content_type in FetchResponseListener::process_response. I decided against this since it expanded the interface of Response and didn't have the same benefits of the first option.

Fixes #24628.


  • ./mach build -d does not report any errors
  • ./mach test-tidy does not report any errors
  • These changes fix #24628.
  • There are tests for these changes
@highfive
Copy link

highfive commented Nov 6, 2019

Thanks for the pull request, and welcome! The Servo team is excited to review your changes, and you should hear from @jdm (or someone else) soon.

@highfive
Copy link

highfive commented Nov 6, 2019

Heads up! This PR modifies the following files:

@jdm
Copy link
Member

jdm commented Nov 12, 2019

Sorry for the review delay, and thanks for the detailed explanation! I agree that this seems like a sensible way to fix the issue.
@bors-servo r+

@bors-servo
Copy link
Contributor

bors-servo commented Nov 12, 2019

📌 Commit 4145d96 has been approved by jdm

@bors-servo
Copy link
Contributor

bors-servo commented Nov 12, 2019

Testing commit 4145d96 with merge da43524...

bors-servo added a commit that referenced this pull request Nov 12, 2019
Set response mime_type based on Content-Type

<!-- Please describe your changes on the following line: -->
Set the response's `mime_type` based on its `Content-Type` header whenever `Response::set_headers` is called. This ensures that `mime_type` is always consistent with `Content-Type`. The other reason for going with this approach is it relies on `extract_mime_type`: https://github.com/servo/servo/blob/afbcbf75eaa63ff0eec8fd3858e9155eb8dbadaa/components/script/dom/headers.rs#L260-L261

Besides the consistency argument, I also expect that we'll update the `extract_mime_type` method to conform with its specification.

Another option I explored was adding a `set_mime_type` member to `Response` and calling that with the mime type from `Metadata::content_type` in `FetchResponseListener::process_response`. I decided against this since it expanded the interface of `Response` and didn't have the same benefits of the first option.

Fixes #24628.

---
<!-- 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 #24628.

<!-- Either: -->
- [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. -->
@bors-servo
Copy link
Contributor

bors-servo commented Nov 12, 2019

💔 Test failed - linux-rel-css

@jdm
Copy link
Member

jdm commented Nov 12, 2019

  ▶ ERROR [expected OK] /fetch/corb/script-html-via-cross-origin-blob-url.sub.html
  │   → expected expression, got '<'
  │ 
  └ blob:http://www1.web-platform.test:8000/814fc97067474afd80a7dda71854d8e8:1:0

That's interesting...

@glowe
Copy link
Author

glowe commented Nov 14, 2019

It looks like setting the mime type is allowing this test (script-html-via-cross-origin-blob-url.sub.html) to progress to a point where it's revealing a bug in the CORB handling in servo. Here's the relevant excerpt:

function step2_processSubframeMsg(msg) {
assert_false(msg.hasOwnProperty('error'), 'unexpected property found: "error"');
assert_equals(msg.blob_type, 'text/html');
assert_equals(msg.blob_size, 147);
// With and without CORB loading of a cross-origin blob should be blocked
// (this is verified by expecting |script.onerror|, but not |script.onload|
// below).
var script = document.createElement("script")
script.src = msg.blob_url;
script.onerror = t.step_func_done(function(){})
script.onload = t.unreached_func("Unexpected load event")
document.body.appendChild(script)

step2_processSubframeMsg is the function that is called when subframe-that-posts-html-containing-blob-url-to-parent.html posts a message back to its parent. Previously, this function was failing at line 23:

assert_equals(msg.blob_type, 'text/html');

Now that the proper mime type is set, the test progresses but errors out later. It looks like Servo is allowing html-correctly-labeled.html to be added to the document as a script element.

The trouble is that this is content actually an HTML page and not javascript, so Servo chokes on the first character of <!DOCTYPE html>. I actually changed the content of html-correctly-labeled.html to javascript and the test continued but failed with:

Screen Shot 2019-11-14 at 12 42 27 AM

Servo should actually block this content from being loaded, but I suspect that we haven't implemented the appropriate CORB checks yet.

One option to move things forward would be to update script-html-via-cross-origin-blob-url.sub.html.ini to expect an ERROR rather than a FAIL. Another option would be to leave this PR open until we've implemented the proper CORB checks.

@jdm
Copy link
Member

jdm commented Nov 14, 2019

Aha, thanks! Your analysis makes complete sense; let's update the expected result since we haven't implemented the CORB specification yet.

Set the response's mime_type based on its Content-Type header whenever
Response::set_headers is called.

Fixes #24628.
@glowe glowe force-pushed the glowe:issue-24628/set-mime-type branch from 4145d96 to e73528e Nov 14, 2019
@jdm
Copy link
Member

jdm commented Nov 18, 2019

@bors-servo
Copy link
Contributor

bors-servo commented Nov 18, 2019

📌 Commit e73528e has been approved by jdm

@bors-servo
Copy link
Contributor

bors-servo commented Nov 18, 2019

Testing commit e73528e with merge 2f44c53...

bors-servo added a commit that referenced this pull request Nov 18, 2019
Set response mime_type based on Content-Type

<!-- Please describe your changes on the following line: -->
Set the response's `mime_type` based on its `Content-Type` header whenever `Response::set_headers` is called. This ensures that `mime_type` is always consistent with `Content-Type`. The other reason for going with this approach is it relies on `extract_mime_type`: https://github.com/servo/servo/blob/afbcbf75eaa63ff0eec8fd3858e9155eb8dbadaa/components/script/dom/headers.rs#L260-L261

Besides the consistency argument, I also expect that we'll update the `extract_mime_type` method to conform with its specification.

Another option I explored was adding a `set_mime_type` member to `Response` and calling that with the mime type from `Metadata::content_type` in `FetchResponseListener::process_response`. I decided against this since it expanded the interface of `Response` and didn't have the same benefits of the first option.

Fixes #24628.

---
<!-- 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 #24628.

<!-- Either: -->
- [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. -->
@bors-servo
Copy link
Contributor

bors-servo commented Nov 18, 2019

💔 Test failed - status-taskcluster

@jdm
Copy link
Member

jdm commented Nov 18, 2019

@bors-servo
Copy link
Contributor

bors-servo commented Nov 18, 2019

Testing commit e73528e with merge 18ab860...

bors-servo added a commit that referenced this pull request Nov 18, 2019
Set response mime_type based on Content-Type

<!-- Please describe your changes on the following line: -->
Set the response's `mime_type` based on its `Content-Type` header whenever `Response::set_headers` is called. This ensures that `mime_type` is always consistent with `Content-Type`. The other reason for going with this approach is it relies on `extract_mime_type`: https://github.com/servo/servo/blob/afbcbf75eaa63ff0eec8fd3858e9155eb8dbadaa/components/script/dom/headers.rs#L260-L261

Besides the consistency argument, I also expect that we'll update the `extract_mime_type` method to conform with its specification.

Another option I explored was adding a `set_mime_type` member to `Response` and calling that with the mime type from `Metadata::content_type` in `FetchResponseListener::process_response`. I decided against this since it expanded the interface of `Response` and didn't have the same benefits of the first option.

Fixes #24628.

---
<!-- 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 #24628.

<!-- Either: -->
- [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. -->
@bors-servo
Copy link
Contributor

bors-servo commented Nov 19, 2019

☀️ Test successful - linux-rel-css, linux-rel-wpt, status-taskcluster
Approved by: jdm
Pushing 18ab860 to master...

@bors-servo bors-servo merged commit e73528e into servo:master Nov 19, 2019
2 checks passed
2 checks passed
Community-TC (pull_request) TaskGroup: success
Details
homu Test successful
Details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

4 participants
You can’t perform that action at this time.