Skip to content

net: send CORS preflight requests to devtools network monitor (#39160) - #49151

Merged
mrobinson merged 2 commits into
servo:mainfrom
willypuzzle:39160-CORS_preflight_requests_donot_appear_in_the_network_monitor
Oct 23, 2026
Merged

mrobinson merged 2 commits into
servo:mainfrom
willypuzzle:39160-CORS_preflight_requests_donot_appear_in_the_network_monitor

Conversation

@willypuzzle

Copy link
Copy Markdown
Contributor

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.

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

@servo-highfive servo-highfive added the S-awaiting-review There is new code that needs to be reviewed. label Oct 21, 2026
@willypuzzle

Copy link
Copy Markdown
Contributor Author

@servo-highfive: assign me

@servo-highfive servo-highfive added the C-assigned There is someone working on resolving the issue label Oct 21, 2026
@servo-highfive

Copy link
Copy Markdown

Hey @willypuzzle! Thanks for your interest in working on this issue. It's now assigned to you!

@willypuzzle
willypuzzle force-pushed the 39160-CORS_preflight_requests_donot_appear_in_the_network_monitor branch 2 times, most recently from 14cd847 to cf290bc Compare October 21, 2026 21:21
@codecov-commenter

Copy link
Copy Markdown

❌ 1 Tests Failed:

Tests completed Failed Passed Skipped
1052 1 1051 0
View the top 1 failed test(s) by shortest run time
servo::largest_contentful_paint::test_largest_contentful_paint_js_api_with_mouse_click_and_reload
Stack Traces | 0.424s run time
thread 'test_largest_contentful_paint_js_api_with_mouse_click_and_reload' (71359) panicked at .../servo/tests/largest_contentful_paint.rs:235:5:
assertion `left == right` failed
  left: 2
 right: 1
stack backtrace:
   0: __rustc::rust_begin_unwind
   1: core::panicking::panic_fmt
   2: core::panicking::assert_failed_inner
   3: core::panicking::assert_failed::<usize, usize>
   4: <largest_contentful_paint::test_largest_contentful_paint_js_api_with_mouse_click_and_reload::{closure#0} as core::ops::function::FnOnce<()>>::call_once
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

To view more test analytics, go to the Test Analytics Dashboard
📋 Got 3 mins? Take this short survey to help us improve Test Analytics.

@willypuzzle
willypuzzle force-pushed the 39160-CORS_preflight_requests_donot_appear_in_the_network_monitor branch 4 times, most recently from 887b3d9 to e8b7204 Compare October 22, 2026 15:22
@willypuzzle

Copy link
Copy Markdown
Contributor Author

@jdm please, would you review this PR? Thanks!

@mrobinson mrobinson left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looks pretty good to me. Just a few minor points about the tests.

Comment thread python/servo/devtools_tests/utils.py Resolved
Comment thread python/servo/devtools_tests/utils.py Resolved
Comment thread python/servo/devtools_tests/utils.py Resolved
Comment thread python/servo/devtools_tests/utils.py Resolved
@servo-highfive servo-highfive added S-needs-code-changes Changes have not yet been made that were requested by a reviewer. S-awaiting-review There is new code that needs to be reviewed. and removed S-awaiting-review There is new code that needs to be reviewed. S-needs-code-changes Changes have not yet been made that were requested by a reviewer. labels Oct 22, 2026
…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]>
@willypuzzle
willypuzzle force-pushed the 39160-CORS_preflight_requests_donot_appear_in_the_network_monitor branch from 90f46bd to 8900cde Compare October 22, 2026 21:50
@willypuzzle

Copy link
Copy Markdown
Contributor Author

@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]>
@willypuzzle
willypuzzle force-pushed the 39160-CORS_preflight_requests_donot_appear_in_the_network_monitor branch from 8900cde to b70d779 Compare October 22, 2026 22:12
@servo-highfive servo-highfive removed the S-awaiting-review There is new code that needs to be reviewed. label Oct 23, 2026
@mrobinson
mrobinson added this pull request to the merge queue Oct 23, 2026
@servo-highfive servo-highfive added the S-awaiting-merge The PR is in the process of compiling and running tests on the automated CI. label Oct 23, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Oct 23, 2026
@servo-highfive servo-highfive added S-tests-failed The changes caused existing tests to fail. and removed S-awaiting-merge The PR is in the process of compiling and running tests on the automated CI. labels Oct 23, 2026
@willypuzzle

Copy link
Copy Markdown
Contributor Author

@jdm @mrobinson I think it failed for reasons that are indipendent from my PR

@mrobinson

Copy link
Copy Markdown
Member

We will need to wait for #49187 to land before landing this one.

@willypuzzle

Copy link
Copy Markdown
Contributor Author

We will need to wait for #49187 to land before landing this one.

@mrobinson Do I need to rebase?

@mrobinson

Copy link
Copy Markdown
Member

@mrobinson Do I need to rebase?

No, the merge queue will take care of rebasing your change.

@mrobinson
mrobinson added this pull request to the merge queue Oct 23, 2026
@servo-highfive servo-highfive added S-awaiting-merge The PR is in the process of compiling and running tests on the automated CI. and removed S-tests-failed The changes caused existing tests to fail. labels Oct 23, 2026
Merged via the queue into servo:main with commit f0d9f7e Oct 23, 2026
41 checks passed
@servo-highfive servo-highfive removed the S-awaiting-merge The PR is in the process of compiling and running tests on the automated CI. label Oct 23, 2026
@willypuzzle
willypuzzle deleted the 39160-CORS_preflight_requests_donot_appear_in_the_network_monitor branch October 23, 2026 13:45
jschwe added a commit to openharmony-rs/servo-ohos that referenced this pull request Oct 30, 2026
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]>
jschwe added a commit to openharmony-rs/servo-ohos that referenced this pull request Nov 9, 2026
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]>
jschwe added a commit to openharmony-rs/servo-ohos that referenced this pull request Nov 10, 2026
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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

C-assigned There is someone working on resolving the issue

Projects

None yet

Development

Successfully merging this pull request may close these issues.

CORS preflight requests do not appear in the network monitor

4 participants