Repository navigation
net: send CORS preflight requests to devtools network monitor (#39160) - #49151
Conversation
|
@servo-highfive: assign me |
|
Hey @willypuzzle! Thanks for your interest in working on this issue. It's now assigned to you! |
14cd847 to
cf290bc
Compare
❌ 1 Tests Failed:
View the top 1 failed test(s) by shortest run time
To view more test analytics, go to the Test Analytics Dashboard |
887b3d9 to
e8b7204
Compare
|
@jdm please, would you review this PR? Thanks! |
mrobinson
left a comment
There was a problem hiding this comment.
Looks pretty good to me. Just a few minor points about the tests.
…39160) Preflight OPTIONS requests were invisible in the network monitor because `cors_preflight_fetch` never notified devtools. Emit the early request, response, and security info events for the preflight, and add a devtools test plus helper utilities to verify the OPTIONS request and its CORS headers show up alongside the actual request. Signed-off-by: Domenico Rizzo <[email protected]>
90f46bd to
8900cde
Compare
|
@mrobinson I addressed all your suggestions, please, would you review again? |
…cript Move the fetch trigger from the test page's inline script into the test itself using a new `trigger` callback in `collect_network_events`, so network watching starts before the request fires instead of relying on a timeout. Also drops a leftover debug print and tightens type hints. Signed-off-by: Domenico Rizzo <[email protected]>
8900cde to
b70d779
Compare
|
@jdm @mrobinson I think it failed for reasons that are indipendent from my PR |
|
We will need to wait for #49187 to land before landing this one. |
@mrobinson Do I need to rebase? |
No, the merge queue will take care of rebasing your change. |
A response body was held twice: as a state in a shared `Arc<Mutex<ResponseBody>>`, and as a `done_chan` that every fetch function passed along and had to reset whenever it replaced the response. Keeping the two paired by convention went wrong in several ways: - A fetch cancelled right after its headers returned a network error while `done_chan` still held a sender, so `wait_for_response` waited forever and the fetch never ended. - A response replaced by a network error, after a failed CORS check or a CORP, CSP, nosniff, MIME type or mixed content block, kept its channel, so its body was still delivered to the consumer. - Step 22 of main fetch (null body status, HEAD) blanked the state, but not the chunks already queued in the channel. - A navigation through a `web+` protocol handler returned a response whose body an inner fetch had already handed to `DiscardFetch`. - Producers had to know whether a consumer inside net (subresource integrity, preloads) needed the whole body, and `file:` and `blob:` bodies were kept whole in net in any case. An in-memory `blob:` body was never kept, so its integrity check always failed. `ResponseBody` is now `Null`, `Bytes`, or a `Stream` of the body stream type added in the previous patch, and the response owns it. `wait_for_response` is the one place that hands a body over, and it keeps the body as `Bytes` for preloads and for subresource integrity. A body whose producer goes away without finishing ends as failed instead of hanging. The body of a redirect, or of a response replaced after a 401 or 407, is discarded instead of being queued while the next request runs; readers of files and of the cache stop when nobody reads their body. `ProtocolHandler::load` loses its `done_chan` parameter, and `servo::protocol_handler` exports the body stream. `Response` is no longer `Clone`: `try_clone` copies a response whose body is not a stream. The page content protocol handler runs main fetch recursively, so the outer fetch hands the handler URL's body over. Otherwise behaviour does not change: a body cut short by the connection still ends as aborted with a successful end of file, a discarded network body is still read to its end so that its connection can be reused and the cache can store it, and subresource integrity still forwards the body before checking it. One exception: a preload whose body is cut short is now kept without a body instead of with the bytes that arrived; both are wrong, and a later patch makes it a network error. Validation: `./mach test-unit -p servo-net`: 490 tests pass, 7 of them new. On ohos-main 67173a4, `test_fetch_cancelled_while_its_headers_are_held_ends` fails with "the fetch did not end", `test_body_of_a_response_that_fails_the_cors_check_is_not_delivered` with all 19 body bytes delivered, `test_body_of_a_response_blocked_by_nosniff_is_not_delivered` with all 12, and `test_navigation_through_a_page_content_protocol_handler_delivers_the_body` with none. Negative controls on this patch: without applying step 22's null body, `test_body_of_a_null_body_status_is_not_delivered` gets 7 bytes; with a test producer that keeps its sender alive, `test_body_whose_producer_stops_without_finishing_ends_the_fetch` does not end; without keeping preloaded bodies, `test_fetch_of_a_preload_keeps_its_body` finds no body. `./mach check`, `./mach clippy --locked -- -- --deny warnings` and `./mach test-tidy` pass. 2026-10-29 sync (CORS cache now in the fetch context): `./mach test-unit --profile checked-release -p servo-net` at this commit, 490 tests pass. AI-assisted: Yes (agent session; the agent wrote this patch and its tests following docs/fetch-body-stream-plan-2026-10-22.md in the workspace, found the cancellation hang, the delivery of blocked bodies and the protocol handler regression, and applied an independent review's findings) AI-assisted: Yes (agent session; 2026-10-29 sync -- conflict resolution, no semantic change: upstream moved the CORS preflight cache into the fetch context (servo#49055, servo#49252), so `main_fetch`, `scheme_fetch`, `http_fetch` and `http_redirect_fetch` lose both the cache and `done_chan`, and the page content protocol handler's inner main fetch no longer passes a fresh cache; the preflight fetch keeps upstream's devtools reporting (servo#49151); `to_filtered` takes the headers out of the internal response before its body-less copy, as upstream now does (servo#49313)) Signed-off-by: Jonathan Schwender <[email protected]>
A response body was held twice: as a state in a shared `Arc<Mutex<ResponseBody>>`, and as a `done_chan` that every fetch function passed along and had to reset whenever it replaced the response. Keeping the two paired by convention went wrong in several ways: - A fetch cancelled right after its headers returned a network error while `done_chan` still held a sender, so `wait_for_response` waited forever and the fetch never ended. - A response replaced by a network error, after a failed CORS check or a CORP, CSP, nosniff, MIME type or mixed content block, kept its channel, so its body was still delivered to the consumer. - Step 22 of main fetch (null body status, HEAD) blanked the state, but not the chunks already queued in the channel. - A navigation through a `web+` protocol handler returned a response whose body an inner fetch had already handed to `DiscardFetch`. - Producers had to know whether a consumer inside net (subresource integrity, preloads) needed the whole body, and `file:` and `blob:` bodies were kept whole in net in any case. An in-memory `blob:` body was never kept, so its integrity check always failed. `ResponseBody` is now `Null`, `Bytes`, or a `Stream` of the body stream type added in the previous patch, and the response owns it. `wait_for_response` is the one place that hands a body over, and it keeps the body as `Bytes` for preloads and for subresource integrity. A body whose producer goes away without finishing ends as failed instead of hanging. The body of a redirect, or of a response replaced after a 401 or 407, is discarded instead of being queued while the next request runs; readers of files and of the cache stop when nobody reads their body. `ProtocolHandler::load` loses its `done_chan` parameter, and `servo::protocol_handler` exports the body stream. `Response` is no longer `Clone`: `try_clone` copies a response whose body is not a stream. The page content protocol handler runs main fetch recursively, so the outer fetch hands the handler URL's body over. Otherwise behaviour does not change: a body cut short by the connection still ends as aborted with a successful end of file, a discarded network body is still read to its end so that its connection can be reused and the cache can store it, and subresource integrity still forwards the body before checking it. One exception: a preload whose body is cut short is now kept without a body instead of with the bytes that arrived; both are wrong, and a later patch makes it a network error. Validation: `./mach test-unit -p servo-net`: 490 tests pass, 7 of them new. On ohos-main 67173a4, `test_fetch_cancelled_while_its_headers_are_held_ends` fails with "the fetch did not end", `test_body_of_a_response_that_fails_the_cors_check_is_not_delivered` with all 19 body bytes delivered, `test_body_of_a_response_blocked_by_nosniff_is_not_delivered` with all 12, and `test_navigation_through_a_page_content_protocol_handler_delivers_the_body` with none. Negative controls on this patch: without applying step 22's null body, `test_body_of_a_null_body_status_is_not_delivered` gets 7 bytes; with a test producer that keeps its sender alive, `test_body_whose_producer_stops_without_finishing_ends_the_fetch` does not end; without keeping preloaded bodies, `test_fetch_of_a_preload_keeps_its_body` finds no body. `./mach check`, `./mach clippy --locked -- -- --deny warnings` and `./mach test-tidy` pass. 2026-10-29 sync (CORS cache now in the fetch context): `./mach test-unit --profile checked-release -p servo-net` at this commit, 490 tests pass. AI-assisted: Yes (agent session; the agent wrote this patch and its tests following docs/fetch-body-stream-plan-2026-10-22.md in the workspace, found the cancellation hang, the delivery of blocked bodies and the protocol handler regression, and applied an independent review's findings) AI-assisted: Yes (agent session; 2026-10-29 sync -- conflict resolution, no semantic change: upstream moved the CORS preflight cache into the fetch context (servo#49055, servo#49252), so `main_fetch`, `scheme_fetch`, `http_fetch` and `http_redirect_fetch` lose both the cache and `done_chan`, and the page content protocol handler's inner main fetch no longer passes a fresh cache; the preflight fetch keeps upstream's devtools reporting (servo#49151); `to_filtered` takes the headers out of the internal response before its body-less copy, as upstream now does (servo#49313)) Signed-off-by: Jonathan Schwender <[email protected]>
A response body was held twice: as a state in a shared `Arc<Mutex<ResponseBody>>`, and as a `done_chan` that every fetch function passed along and had to reset whenever it replaced the response. Keeping the two paired by convention went wrong in several ways: - A fetch cancelled right after its headers returned a network error while `done_chan` still held a sender, so `wait_for_response` waited forever and the fetch never ended. - A response replaced by a network error, after a failed CORS check or a CORP, CSP, nosniff, MIME type or mixed content block, kept its channel, so its body was still delivered to the consumer. - Step 22 of main fetch (null body status, HEAD) blanked the state, but not the chunks already queued in the channel. - A navigation through a `web+` protocol handler returned a response whose body an inner fetch had already handed to `DiscardFetch`. - Producers had to know whether a consumer inside net (subresource integrity, preloads) needed the whole body, and `file:` and `blob:` bodies were kept whole in net in any case. An in-memory `blob:` body was never kept, so its integrity check always failed. `ResponseBody` is now `Null`, `Bytes`, or a `Stream` of the body stream type added in the previous patch, and the response owns it. `wait_for_response` is the one place that hands a body over, and it keeps the body as `Bytes` for preloads and for subresource integrity. A body whose producer goes away without finishing ends as failed instead of hanging. The body of a redirect, or of a response replaced after a 401 or 407, is discarded instead of being queued while the next request runs; readers of files and of the cache stop when nobody reads their body. `ProtocolHandler::load` loses its `done_chan` parameter, and `servo::protocol_handler` exports the body stream. `Response` is no longer `Clone`: `try_clone` copies a response whose body is not a stream. The page content protocol handler runs main fetch recursively, so the outer fetch hands the handler URL's body over. Otherwise behaviour does not change: a body cut short by the connection still ends as aborted with a successful end of file, a discarded network body is still read to its end so that its connection can be reused and the cache can store it, and subresource integrity still forwards the body before checking it. One exception: a preload whose body is cut short is now kept without a body instead of with the bytes that arrived; both are wrong, and a later patch makes it a network error. Validation: `./mach test-unit -p servo-net`: 490 tests pass, 7 of them new. On ohos-main 67173a4, `test_fetch_cancelled_while_its_headers_are_held_ends` fails with "the fetch did not end", `test_body_of_a_response_that_fails_the_cors_check_is_not_delivered` with all 19 body bytes delivered, `test_body_of_a_response_blocked_by_nosniff_is_not_delivered` with all 12, and `test_navigation_through_a_page_content_protocol_handler_delivers_the_body` with none. Negative controls on this patch: without applying step 22's null body, `test_body_of_a_null_body_status_is_not_delivered` gets 7 bytes; with a test producer that keeps its sender alive, `test_body_whose_producer_stops_without_finishing_ends_the_fetch` does not end; without keeping preloaded bodies, `test_fetch_of_a_preload_keeps_its_body` finds no body. `./mach check`, `./mach clippy --locked -- -- --deny warnings` and `./mach test-tidy` pass. 2026-10-29 sync (CORS cache now in the fetch context): `./mach test-unit --profile checked-release -p servo-net` at this commit, 490 tests pass. AI-assisted: Yes (agent session; the agent wrote this patch and its tests following docs/fetch-body-stream-plan-2026-10-22.md in the workspace, found the cancellation hang, the delivery of blocked bodies and the protocol handler regression, and applied an independent review's findings) AI-assisted: Yes (agent session; 2026-10-29 sync -- conflict resolution, no semantic change: upstream moved the CORS preflight cache into the fetch context (servo#49055, servo#49252), so `main_fetch`, `scheme_fetch`, `http_fetch` and `http_redirect_fetch` lose both the cache and `done_chan`, and the page content protocol handler's inner main fetch no longer passes a fresh cache; the preflight fetch keeps upstream's devtools reporting (servo#49151); `to_filtered` takes the headers out of the internal response before its body-less copy, as upstream now does (servo#49313)) Signed-off-by: Jonathan Schwender <[email protected]>
Preflight OPTIONS requests were invisible in the network monitor because
cors_preflight_fetchnever notified devtools. Emit the early request, response, and security info events for the preflight, and add a devtools test plus helper utilities to verify the OPTIONS request and its CORS headers show up alongside the actual request.Testing: Added a test_cors_preflight in devtools_tests. It test that the devtool shows the option preflight call in case of cors necessity. It is made of three parts: helpers in utils, the test itself and a html file that conditionally calls a cors protected url if a right parameter is passed as query string.
Fixes: #39160