Send early DevToolsHttpRequest and relocate response reporting to main_fetch (#37906)

This change refactors how we notify DevTools about network activity so
that all fetches (even those served from cache) appear correctly in the
Network panel, and so that DevTools sees request metadata as soon as
possible rather than waiting until the end of a full HTTP cycle.
- Before, we only send DevTools events inside http_network_fetch, so
cached responses (which skip that path) never show up. By emitting a
minimal HttpRequest event at the very start of main_fetch (with URL,
method, pipeline and browsing IDs), we guarantee every fetch shows up
immediately.
- Then, by moving HttpResponse notifications out of http_network_fetch
into main_fetch (right after process_response and process_response_eof),
we ensure DevTools gets status, header, and completion events for both
network and cache hits. Leveraging nullable fields in NetworkEventActor
lets us incrementally fill in timing, header, and body data later,
improving DevTools’ visibility.
Testing: Ran servo with `--devtools=6080` flag, cached responses now
appear in the network panel
Fixes: https://github.com/servo/servo/issues/37869

---------

Signed-off-by: Uthman Yahaya Baba <uthmanyahayababa@gmail.com>
This commit is contained in:
Usman Yahaya Baba 2025-07-15 06:41:11 +01:00 committed by GitHub
parent 0e3165da01
commit ff02fdad6d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 136 additions and 79 deletions

View file

@ -42,7 +42,10 @@ use super::fetch_params::FetchParams;
use crate::fetch::cors_cache::CorsCache;
use crate::fetch::headers::determine_nosniff;
use crate::filemanager_thread::FileManager;
use crate::http_loader::{HttpState, determine_requests_referrer, http_fetch, set_default_accept};
use crate::http_loader::{
HttpState, determine_requests_referrer, http_fetch, send_early_httprequest_to_devtools,
send_response_to_devtools, set_default_accept,
};
use crate::protocols::{ProtocolRegistry, is_url_potentially_trustworthy};
use crate::request_interceptor::RequestInterceptor;
use crate::subresource_integrity::is_response_integrity_valid;
@ -257,7 +260,8 @@ pub async fn main_fetch(
) -> Response {
// Step 1: Let request be fetchParam's request.
let request = &mut fetch_params.request;
// send early HTTP request to DevTools
send_early_httprequest_to_devtools(request, context);
// Step 2: Let response be null.
let mut response = None;
@ -701,6 +705,8 @@ pub async fn main_fetch(
// Step 22.
target.process_response(request, &response);
// Send Response to Devtools
send_response_to_devtools(request, context, &response);
// Step 23.
if !response_loaded {
@ -709,6 +715,10 @@ pub async fn main_fetch(
// Step 24.
target.process_response_eof(request, &response);
// Send Response to Devtools
// This is done after process_response_eof to ensure that the body is fully
// processed before sending the response to Devtools.
send_response_to_devtools(request, context, &response);
if let Ok(http_cache) = context.state.http_cache.write() {
http_cache.update_awaiting_consumers(request, &response);