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

XMLHttpRequest: Content-Length tests #27837

Merged
merged 4 commits into from
Mar 10, 2021
Merged

Conversation

annevk
Copy link
Member

@annevk annevk commented Mar 1, 2021

Some tests with progress events, Content-Length, and service workers.

Primarily for whatwg/fetch#604.

Some tests with progress events, Content-Length, and service workers.
@github-actions github-actions bot temporarily deployed to wpt-preview-27837 March 1, 2021 15:29 Inactive
@annevk annevk mentioned this pull request Mar 1, 2021
annevk added a commit to whatwg/fetch that referenced this pull request Mar 1, 2021
As the body concept is refactored for #604, XMLHttpRequest will need to use this algorithm for its events. We also want to require browsers to use this algorithm instead of the one defined by HTTP as part of #1156.

Tests: web-platform-tests/wpt#10548 & web-platform-tests/wpt#27837.
annevk added a commit to whatwg/fetch that referenced this pull request Mar 1, 2021
Together with #1183 this solves the Fetch side of #604. Changes:

* No longer set a length for network responses. Callers will have to parse Content-Length themselves.
* Make extract set length so requests will set Content-Length correctly.

XMLHttpRequest PR: TODO.

Tests: web-platform-tests/wpt#27837.
annevk added a commit to whatwg/xhr that referenced this pull request Mar 2, 2021
The only information browsers use for progress events for responses is the Content-Length header.

Align on that and only use body's length concept for uploads.

Tests: web-platform-tests/wpt#27837.

Fetch PRs: whatwg/fetch#1183 & whatwg/fetch#1184.
annevk added a commit to whatwg/xhr that referenced this pull request Mar 2, 2021
The only information browsers use for progress events for responses is the Content-Length header.

Align on that and only use body's length concept for uploads.

Tests: web-platform-tests/wpt#27837.

Fetch PRs: whatwg/fetch#1183 & whatwg/fetch#1184.
resolve();
});
});
}, `Synthetic response with two Content-Length headers value larger than response body length`);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test captured the main weirdness. Somehow Chrome and Firefox (not sure how to run service worker tests in Safari yet) return "10000" despite the synthetic response having two Content-Length headers.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mfalken what do you think about this behavior? Chromium generates net::ERR_RESPONSE_HEADERS_MULTIPLE_CONTENT_LENGTH for multiple content-length headers in response coming from the network[1], but that seems missing in the service worker case[2].

1: https://source.chromium.org/chromium/chromium/src/+/master:net/http/http_stream_parser.cc;l=1043?q=RESPONSE_HEADERS_MULTIPLE_CONTENT_LENGTH%20file:net%2F&ss=chromium
2: https://source.chromium.org/chromium/chromium/src/+/master:content/common/service_worker/service_worker_loader_helpers.cc;l=89;drc=56c01dcef367cdbda4e2592a9d0d897f8272fdc7

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Without really knowing about the "response smuggling attack" cited in the comment, I would tend to say Chrome should treat responses from the SW and from the network as much as possible, so I think we should throw the same network error.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. I think I disagree, as we it's only about handing a Response over a thread boundary.
  2. This does not create a network error in Chrome today for a response coming from the network. Multiple Content-Length headers with the same value are fine.
  3. If we did want to error for multiple Content-Length headers in a synthetic response where the headers have different values, we have to do a lot more work in writing those kind of conditions down.
  4. The problem here is that Chrome (and Firefox) return(s) 10000 rather than 10000, 10000. In Firefox that happens because the header lookup code apparently special cases Content-Length...

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@yutakahirano @mfalken is there a way we can move this forward? I suppose I can add a test for the network equivalent (which will likely also fail, but not because the response is rejected, as per above), though it's a bit out-of-scope for what I was going for it does seem good to test. Anything else?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So I went ahead and added a test for this and it seems that Chrome doesn't have any problems with duplicates from the network (but Firefox and Safari do). Convincing enough?

Copy link
Contributor

@yutakahirano yutakahirano Mar 10, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't have a strong opinion here and would like to defer to @mfalken. I'm fine with the change overall.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I filed w3c/ServiceWorker#1571 as follow-up as this matches the current specification.

annevk added a commit to whatwg/xhr that referenced this pull request Mar 3, 2021
The only information browsers use for progress events for responses is the Content-Length header.

Align on that and only use body's length concept for uploads.

Tests: web-platform-tests/wpt#27837.

Fetch PRs: whatwg/fetch#1183 & whatwg/fetch#1184.
@annevk annevk requested a review from yutakahirano March 3, 2021 16:48
@annevk annevk requested a review from yutakahirano March 4, 2021 10:18
@github-actions github-actions bot temporarily deployed to wpt-preview-27837 March 4, 2021 10:19 Inactive
resolve();
});
});
}, `Synthetic response with two Content-Length headers value larger than response body length`);
Copy link
Contributor

@yutakahirano yutakahirano Mar 10, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't have a strong opinion here and would like to defer to @mfalken. I'm fine with the change overall.

@github-actions github-actions bot had a problem deploying to wpt-preview-27837 March 10, 2021 10:39 Error
@annevk annevk merged commit 0adf967 into master Mar 10, 2021
@annevk annevk deleted the annevk/xhr-and-content-length branch March 10, 2021 11:07
annevk added a commit to whatwg/fetch that referenced this pull request Mar 10, 2021
Together with #1183 this solves the Fetch side of #604. Changes:

* No longer set a length for network responses. Callers will have to parse Content-Length themselves.
* Make extract set length so requests can set Content-Length correctly.

XMLHttpRequest PR: whatwg/xhr#317.

Tests: web-platform-tests/wpt#27837.
annevk added a commit to whatwg/xhr that referenced this pull request Mar 11, 2021
The only information browsers use for progress events for responses is the Content-Length header.

Align on that and only use body's length concept for uploads.

Tests: web-platform-tests/wpt#27837.

Fetch PRs: whatwg/fetch#1183 & whatwg/fetch#1184.

Closes whatwg/fetch#604.
@wanderview
Copy link
Member

@annevk xhr-content-length.window.js is broken on all browsers:

https://wpt.fyi/results/service-workers/service-worker/xhr-content-length.window.html?label=experimental&label=master&aligned

Because service workers require https. Can you please update the test to use https.js filename?

Bishwarupjee pushed a commit to Bishwarupjee/xhr that referenced this pull request Jan 31, 2024
The only information browsers use for progress events for responses is the Content-Length header.

Align on that and only use body's length concept for uploads.

Tests: web-platform-tests/wpt#27837.

Fetch PRs: whatwg/fetch#1183 & whatwg/fetch#1184.

Closes whatwg/fetch#604.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants