-
Notifications
You must be signed in to change notification settings - Fork 350
Tee request body on ServiceWorker interception #1144
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
Conversation
So what's the idea for non-streaming bodies that end up consumed by the service worker? It seems you decided to not clone the request for those scenarios? |
Sorry you're right. The latest PR includes an explicit copy step. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good I think, but unlike https://fetch.spec.whatwg.org/#concept-http-network-or-cache-fetch we do not copy request here. Is request's body the only thing the service worker can affect? Is the headers list immutable? (I'm not saying this needs to change, but I'd like to ensure we have the right setup here.)
I'd also appreciate review from @wanderview and @jakearchibald.
The latest PR creates a copy of a request. |
Could you explain why you make a copy? |
To make it clear that request mutation in service worker doesn't affect the network network. |
Yeah I was wondering if that was possible, but looking at https://w3c.github.io/ServiceWorker/#on-fetch-request-algorithm |
Reverted the change partially. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, but it isn't clear to me why the body is copied
fetch.bs
Outdated
<a for=/>body</a>. | ||
|
||
<li> | ||
<p>Let <var>savedBody</var> be a copy of <var>request</var>'s <a for=request>body</a>. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the benefit of copying the body at this point?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When calling clone()
in the service worker it modifies reuqests.body. So we want to keep the original body.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense! Might be worth putting that in a note?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure I understand. If you clone a request it uses https://fetch.spec.whatwg.org/#concept-body-clone to clone its body, right? This updates body's stream to a non-null value but its source remains the same. Couldn't we always extract from source again?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The point I'm trying to make is that it overwrites the request's body's stream and that means request will not be disturbed nor locked. I'd like to fail the request in such a case too (if other conditions are met). This corresponds to "clone-and-ignore" tests in web-platform-tests/wpt#27325.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we tee the request body before passing it to the service worker (it is hard to implement TBH - I think we will not be able to implement it in the first release), I would like to allow reading the body in the network fallback case. I'm uncomfortable with having magic in the clone operation, and that is more important to me than enforcing the "read once" rule. @annevk, what do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can't we check if request's body's source is null and request's body's stream is disturbed or locked before we want to return null?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do yo prefer global "read once" rule to a stream body?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To give web developers an API that's as consistent as possible and also give implementations freedom to experiment with various memory optimization techniques.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, now it clones the original request. I'm going to fix w3c/ServiceWorker#1563.
847abbc
to
1705760
Compare
@yutakahirano I don't see the closing of these streams as @jakearchibald suggested. Don't we need to do that? I guess it's not strictly speaking observable, but it seems somewhat bad to have a leak. I like how this ended up being a lot simpler than some of the earlier approaches. |
I added a cancel step at in w3c/ServiceWorker#1563. |
Shouldn't we close request here as well if we got a response back? We might also want to explain in a note what the setup is here. |
That is #572, I think (and yes, I think we should cancel it instead of transmitting). |
Yeah, I'm thinking that we should fix #572 as you suggested after all. In that only the network layer attempts to transmit chunks. |
Thank you! |
Tests for whatwg/fetch#1144 and w3c/ServiceWorker#1563. Co-authored-by: Yutaka Hirano <[email protected]> Co-authored-by: Anne van Kesteren <[email protected]>
This partially implements whatwg/fetch#1144 and w3c/ServiceWorker#1560. ServiceWorkerSubresourceLoader reuses the request body in the original request in the network fallback case (ServiceWorkerSubresourceLoader::OnFallback). This is problematic for a request with streaming upload body, because the body is not copyable. Ideally we should tee the body as specified in whatwg/fetch#1144 and w3c/ServiceWorker#1560, but this CL stops passing the body to the service worker instead to unblock the origin trial, assuming that few users care about the streaming body in the service worker. Bug: 1165690 Change-Id: Ie1d2d2fd74990b1bf7f9b10e55710a644871cc60
This partially implements whatwg/fetch#1144 and w3c/ServiceWorker#1560. ServiceWorkerSubresourceLoader reuses the request body in the original request in the network fallback case (ServiceWorkerSubresourceLoader::OnFallback). This is problematic for a request with streaming upload body, because the body is not copyable. Ideally we should tee the body as specified in whatwg/fetch#1144 and w3c/ServiceWorker#1560, but this CL stops passing the body to the service worker instead to unblock the origin trial, assuming that few users care about the streaming body in the service worker. Bug: 1165690 Change-Id: Ie1d2d2fd74990b1bf7f9b10e55710a644871cc60
This partially implements whatwg/fetch#1144 and w3c/ServiceWorker#1560. ServiceWorkerSubresourceLoader reuses the request body in the original request in the network fallback case (ServiceWorkerSubresourceLoader::OnFallback). This is problematic for a request with streaming upload body, because the body is not copyable. Ideally we should tee the body as specified in whatwg/fetch#1144 and w3c/ServiceWorker#1560, but this CL stops passing the body to the service worker instead to unblock the origin trial, assuming that few users care about the streaming body in the service worker. Bug: 1165690 Change-Id: Ie1d2d2fd74990b1bf7f9b10e55710a644871cc60
…before network fallback, a=testonly Automatic update from web-platform-tests Test cases where request body gets used before network fallback (#27325) Tests for whatwg/fetch#1144 and w3c/ServiceWorker#1563. Co-authored-by: Yutaka Hirano <[email protected]> Co-authored-by: Anne van Kesteren <[email protected]> -- wpt-commits: c30545df6a50c61f3673ed952c78c0a607100d45 wpt-pr: 27325
…before network fallback, a=testonly Automatic update from web-platform-tests Test cases where request body gets used before network fallback (#27325) Tests for whatwg/fetch#1144 and w3c/ServiceWorker#1563. Co-authored-by: Yutaka Hirano <yhiranochrmomium.org> Co-authored-by: Anne van Kesteren <annevkannevk.nl> -- wpt-commits: c30545df6a50c61f3673ed952c78c0a607100d45 wpt-pr: 27325 UltraBlame original commit: fc2a98935821f5df9bf73b8642ff68ab95e1ea17
…before network fallback, a=testonly Automatic update from web-platform-tests Test cases where request body gets used before network fallback (#27325) Tests for whatwg/fetch#1144 and w3c/ServiceWorker#1563. Co-authored-by: Yutaka Hirano <yhiranochrmomium.org> Co-authored-by: Anne van Kesteren <annevkannevk.nl> -- wpt-commits: c30545df6a50c61f3673ed952c78c0a607100d45 wpt-pr: 27325 UltraBlame original commit: fc2a98935821f5df9bf73b8642ff68ab95e1ea17
…before network fallback, a=testonly Automatic update from web-platform-tests Test cases where request body gets used before network fallback (#27325) Tests for whatwg/fetch#1144 and w3c/ServiceWorker#1563. Co-authored-by: Yutaka Hirano <yhiranochrmomium.org> Co-authored-by: Anne van Kesteren <annevkannevk.nl> -- wpt-commits: c30545df6a50c61f3673ed952c78c0a607100d45 wpt-pr: 27325 UltraBlame original commit: fc2a98935821f5df9bf73b8642ff68ab95e1ea17
This partially implements whatwg/fetch#1144 and w3c/ServiceWorker#1560. ServiceWorkerSubresourceLoader reuses the request body in the original request in the network fallback case (ServiceWorkerSubresourceLoader::OnFallback). This is problematic for a request with streaming upload body, because the body is not copyable. Ideally we should tee the body as specified in whatwg/fetch#1144 and w3c/ServiceWorker#1560, but this CL stops passing the body to the service worker instead to unblock the origin trial, assuming that few users care about the streaming body in the service worker. Bug: 1165690 Change-Id: Ie1d2d2fd74990b1bf7f9b10e55710a644871cc60
This partially implements whatwg/fetch#1144 and w3c/ServiceWorker#1560. ServiceWorkerSubresourceLoader reuses the request body in the original request in the network fallback case (ServiceWorkerSubresourceLoader::OnFallback). This is problematic for a request with streaming upload body, because the body is not copyable. Ideally we should tee the body as specified in whatwg/fetch#1144 and w3c/ServiceWorker#1560, but this CL stops passing the body to the service worker instead to unblock the origin trial, assuming that few users care about the streaming body in the service worker. Bug: 1165690 Change-Id: Ie1d2d2fd74990b1bf7f9b10e55710a644871cc60 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2712842 Reviewed-by: Matt Falkenhagen <[email protected]> Reviewed-by: Yoichi Osato <[email protected]> Reviewed-by: Kinuko Yasuda <[email protected]> Auto-Submit: Yutaka Hirano <[email protected]> Commit-Queue: Yutaka Hirano <[email protected]> Cr-Commit-Position: refs/heads/master@{#857605}
This partially implements whatwg/fetch#1144 and w3c/ServiceWorker#1560. ServiceWorkerSubresourceLoader reuses the request body in the original request in the network fallback case (ServiceWorkerSubresourceLoader::OnFallback). This is problematic for a request with streaming upload body, because the body is not copyable. Ideally we should tee the body as specified in whatwg/fetch#1144 and w3c/ServiceWorker#1560, but this CL stops passing the body to the service worker instead to unblock the origin trial, assuming that few users care about the streaming body in the service worker. Bug: 1165690 Change-Id: Ie1d2d2fd74990b1bf7f9b10e55710a644871cc60 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2712842 Reviewed-by: Matt Falkenhagen <[email protected]> Reviewed-by: Yoichi Osato <[email protected]> Reviewed-by: Kinuko Yasuda <[email protected]> Auto-Submit: Yutaka Hirano <[email protected]> Commit-Queue: Yutaka Hirano <[email protected]> Cr-Commit-Position: refs/heads/master@{#857605}
This partially implements whatwg/fetch#1144 and w3c/ServiceWorker#1560. ServiceWorkerSubresourceLoader reuses the request body in the original request in the network fallback case (ServiceWorkerSubresourceLoader::OnFallback). This is problematic for a request with streaming upload body, because the body is not copyable. Ideally we should tee the body as specified in whatwg/fetch#1144 and w3c/ServiceWorker#1560, but this CL stops passing the body to the service worker instead to unblock the origin trial, assuming that few users care about the streaming body in the service worker. Bug: 1165690 Change-Id: Ie1d2d2fd74990b1bf7f9b10e55710a644871cc60 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2712842 Reviewed-by: Matt Falkenhagen <[email protected]> Reviewed-by: Yoichi Osato <[email protected]> Reviewed-by: Kinuko Yasuda <[email protected]> Auto-Submit: Yutaka Hirano <[email protected]> Commit-Queue: Yutaka Hirano <[email protected]> Cr-Commit-Position: refs/heads/master@{#857605}
…before network fallback, a=testonly Automatic update from web-platform-tests Test cases where request body gets used before network fallback (#27325) Tests for whatwg/fetch#1144 and w3c/ServiceWorker#1563. Co-authored-by: Yutaka Hirano <[email protected]> Co-authored-by: Anne van Kesteren <[email protected]> -- wpt-commits: c30545df6a50c61f3673ed952c78c0a607100d45 wpt-pr: 27325
…before network fallback, a=testonly Automatic update from web-platform-tests Test cases where request body gets used before network fallback (#27325) Tests for whatwg/fetch#1144 and w3c/ServiceWorker#1563. Co-authored-by: Yutaka Hirano <[email protected]> Co-authored-by: Anne van Kesteren <[email protected]> -- wpt-commits: c30545df6a50c61f3673ed952c78c0a607100d45 wpt-pr: 27325
…before network fallback, a=testonly Automatic update from web-platform-tests Test cases where request body gets used before network fallback (#27325) Tests for whatwg/fetch#1144 and w3c/ServiceWorker#1563. Co-authored-by: Yutaka Hirano <[email protected]> Co-authored-by: Anne van Kesteren <[email protected]> -- wpt-commits: c30545df6a50c61f3673ed952c78c0a607100d45 wpt-pr: 27325
…before network fallback, a=testonly Automatic update from web-platform-tests Test cases where request body gets used before network fallback (#27325) Tests for whatwg/fetch#1144 and w3c/ServiceWorker#1563. Co-authored-by: Yutaka Hirano <yhiranochrmomium.org> Co-authored-by: Anne van Kesteren <annevkannevk.nl> -- wpt-commits: c30545df6a50c61f3673ed952c78c0a607100d45 wpt-pr: 27325 UltraBlame original commit: 2472b38eb2f886421d5a062314a87dc33029a393
…before network fallback, a=testonly Automatic update from web-platform-tests Test cases where request body gets used before network fallback (#27325) Tests for whatwg/fetch#1144 and w3c/ServiceWorker#1563. Co-authored-by: Yutaka Hirano <yhiranochrmomium.org> Co-authored-by: Anne van Kesteren <annevkannevk.nl> -- wpt-commits: c30545df6a50c61f3673ed952c78c0a607100d45 wpt-pr: 27325 UltraBlame original commit: 02b382fb279e8edb2435787d95fd519f036320b3
…before network fallback, a=testonly Automatic update from web-platform-tests Test cases where request body gets used before network fallback (#27325) Tests for whatwg/fetch#1144 and w3c/ServiceWorker#1563. Co-authored-by: Yutaka Hirano <yhiranochrmomium.org> Co-authored-by: Anne van Kesteren <annevkannevk.nl> -- wpt-commits: c30545df6a50c61f3673ed952c78c0a607100d45 wpt-pr: 27325 UltraBlame original commit: 2472b38eb2f886421d5a062314a87dc33029a393
…before network fallback, a=testonly Automatic update from web-platform-tests Test cases where request body gets used before network fallback (#27325) Tests for whatwg/fetch#1144 and w3c/ServiceWorker#1563. Co-authored-by: Yutaka Hirano <yhiranochrmomium.org> Co-authored-by: Anne van Kesteren <annevkannevk.nl> -- wpt-commits: c30545df6a50c61f3673ed952c78c0a607100d45 wpt-pr: 27325 UltraBlame original commit: 02b382fb279e8edb2435787d95fd519f036320b3
…before network fallback, a=testonly Automatic update from web-platform-tests Test cases where request body gets used before network fallback (#27325) Tests for whatwg/fetch#1144 and w3c/ServiceWorker#1563. Co-authored-by: Yutaka Hirano <yhiranochrmomium.org> Co-authored-by: Anne van Kesteren <annevkannevk.nl> -- wpt-commits: c30545df6a50c61f3673ed952c78c0a607100d45 wpt-pr: 27325 UltraBlame original commit: 2472b38eb2f886421d5a062314a87dc33029a393
…before network fallback, a=testonly Automatic update from web-platform-tests Test cases where request body gets used before network fallback (#27325) Tests for whatwg/fetch#1144 and w3c/ServiceWorker#1563. Co-authored-by: Yutaka Hirano <yhiranochrmomium.org> Co-authored-by: Anne van Kesteren <annevkannevk.nl> -- wpt-commits: c30545df6a50c61f3673ed952c78c0a607100d45 wpt-pr: 27325 UltraBlame original commit: 02b382fb279e8edb2435787d95fd519f036320b3
…fallback on service worker, a=testonly Automatic update from web-platform-tests Make streaming upload work with network fallback on service worker This partially implements whatwg/fetch#1144 and w3c/ServiceWorker#1560. ServiceWorkerSubresourceLoader reuses the request body in the original request in the network fallback case (ServiceWorkerSubresourceLoader::OnFallback). This is problematic for a request with streaming upload body, because the body is not copyable. Ideally we should tee the body as specified in whatwg/fetch#1144 and w3c/ServiceWorker#1560, but this CL stops passing the body to the service worker instead to unblock the origin trial, assuming that few users care about the streaming body in the service worker. Bug: 1165690 Change-Id: Ie1d2d2fd74990b1bf7f9b10e55710a644871cc60 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2712842 Reviewed-by: Matt Falkenhagen <[email protected]> Reviewed-by: Yoichi Osato <[email protected]> Reviewed-by: Kinuko Yasuda <[email protected]> Auto-Submit: Yutaka Hirano <[email protected]> Commit-Queue: Yutaka Hirano <[email protected]> Cr-Commit-Position: refs/heads/master@{#857605} -- wpt-commits: ecb2781e1fde45e5ed70019f5ac9e14dfec065d1 wpt-pr: 27756
…fallback on service worker, a=testonly Automatic update from web-platform-tests Make streaming upload work with network fallback on service worker This partially implements whatwg/fetch#1144 and w3c/ServiceWorker#1560. ServiceWorkerSubresourceLoader reuses the request body in the original request in the network fallback case (ServiceWorkerSubresourceLoader::OnFallback). This is problematic for a request with streaming upload body, because the body is not copyable. Ideally we should tee the body as specified in whatwg/fetch#1144 and w3c/ServiceWorker#1560, but this CL stops passing the body to the service worker instead to unblock the origin trial, assuming that few users care about the streaming body in the service worker. Bug: 1165690 Change-Id: Ie1d2d2fd74990b1bf7f9b10e55710a644871cc60 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2712842 Reviewed-by: Matt Falkenhagen <falkenchromium.org> Reviewed-by: Yoichi Osato <yoichiochromium.org> Reviewed-by: Kinuko Yasuda <kinukochromium.org> Auto-Submit: Yutaka Hirano <yhiranochromium.org> Commit-Queue: Yutaka Hirano <yhiranochromium.org> Cr-Commit-Position: refs/heads/master{#857605} -- wpt-commits: ecb2781e1fde45e5ed70019f5ac9e14dfec065d1 wpt-pr: 27756 UltraBlame original commit: 4bd27f41c457d02f5cd92bc5fae91f98f8149b3d
…fallback on service worker, a=testonly Automatic update from web-platform-tests Make streaming upload work with network fallback on service worker This partially implements whatwg/fetch#1144 and w3c/ServiceWorker#1560. ServiceWorkerSubresourceLoader reuses the request body in the original request in the network fallback case (ServiceWorkerSubresourceLoader::OnFallback). This is problematic for a request with streaming upload body, because the body is not copyable. Ideally we should tee the body as specified in whatwg/fetch#1144 and w3c/ServiceWorker#1560, but this CL stops passing the body to the service worker instead to unblock the origin trial, assuming that few users care about the streaming body in the service worker. Bug: 1165690 Change-Id: Ie1d2d2fd74990b1bf7f9b10e55710a644871cc60 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2712842 Reviewed-by: Matt Falkenhagen <falkenchromium.org> Reviewed-by: Yoichi Osato <yoichiochromium.org> Reviewed-by: Kinuko Yasuda <kinukochromium.org> Auto-Submit: Yutaka Hirano <yhiranochromium.org> Commit-Queue: Yutaka Hirano <yhiranochromium.org> Cr-Commit-Position: refs/heads/master{#857605} -- wpt-commits: ecb2781e1fde45e5ed70019f5ac9e14dfec065d1 wpt-pr: 27756 UltraBlame original commit: 4bd27f41c457d02f5cd92bc5fae91f98f8149b3d
…fallback on service worker, a=testonly Automatic update from web-platform-tests Make streaming upload work with network fallback on service worker This partially implements whatwg/fetch#1144 and w3c/ServiceWorker#1560. ServiceWorkerSubresourceLoader reuses the request body in the original request in the network fallback case (ServiceWorkerSubresourceLoader::OnFallback). This is problematic for a request with streaming upload body, because the body is not copyable. Ideally we should tee the body as specified in whatwg/fetch#1144 and w3c/ServiceWorker#1560, but this CL stops passing the body to the service worker instead to unblock the origin trial, assuming that few users care about the streaming body in the service worker. Bug: 1165690 Change-Id: Ie1d2d2fd74990b1bf7f9b10e55710a644871cc60 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2712842 Reviewed-by: Matt Falkenhagen <falkenchromium.org> Reviewed-by: Yoichi Osato <yoichiochromium.org> Reviewed-by: Kinuko Yasuda <kinukochromium.org> Auto-Submit: Yutaka Hirano <yhiranochromium.org> Commit-Queue: Yutaka Hirano <yhiranochromium.org> Cr-Commit-Position: refs/heads/master{#857605} -- wpt-commits: ecb2781e1fde45e5ed70019f5ac9e14dfec065d1 wpt-pr: 27756 UltraBlame original commit: 4bd27f41c457d02f5cd92bc5fae91f98f8149b3d
…before network fallback, a=testonly Automatic update from web-platform-tests Test cases where request body gets used before network fallback (#27325) Tests for whatwg/fetch#1144 and w3c/ServiceWorker#1563. Co-authored-by: Yutaka Hirano <[email protected]> Co-authored-by: Anne van Kesteren <[email protected]> -- wpt-commits: c30545df6a50c61f3673ed952c78c0a607100d45 wpt-pr: 27325
(See WHATWG Working Mode: Changes for more details.)
Fixes w3c/ServiceWorker#1560, fixes #572.
Preview | Diff