mirror of
https://github.com/servo/servo.git
synced 2025-08-06 14:10:11 +01:00
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:
parent
0e3165da01
commit
ff02fdad6d
8 changed files with 136 additions and 79 deletions
|
@ -417,12 +417,12 @@ fn prepare_devtools_request(
|
|||
is_xhr,
|
||||
browsing_context_id,
|
||||
};
|
||||
let net_event = NetworkEvent::HttpRequest(request);
|
||||
let net_event = NetworkEvent::HttpRequestUpdate(request);
|
||||
|
||||
ChromeToDevtoolsControlMsg::NetworkEvent(request_id, net_event)
|
||||
}
|
||||
|
||||
fn send_request_to_devtools(
|
||||
pub fn send_request_to_devtools(
|
||||
msg: ChromeToDevtoolsControlMsg,
|
||||
devtools_chan: &Sender<DevtoolsControlMsg>,
|
||||
) {
|
||||
|
@ -431,25 +431,74 @@ fn send_request_to_devtools(
|
|||
.unwrap();
|
||||
}
|
||||
|
||||
fn send_response_to_devtools(
|
||||
devtools_chan: &Sender<DevtoolsControlMsg>,
|
||||
request_id: String,
|
||||
headers: Option<HeaderMap>,
|
||||
status: HttpStatus,
|
||||
pipeline_id: PipelineId,
|
||||
browsing_context_id: BrowsingContextId,
|
||||
pub fn send_response_to_devtools(
|
||||
request: &mut Request,
|
||||
context: &FetchContext,
|
||||
response: &Response,
|
||||
) {
|
||||
let response = DevtoolsHttpResponse {
|
||||
headers,
|
||||
status,
|
||||
body: None,
|
||||
pipeline_id,
|
||||
browsing_context_id,
|
||||
};
|
||||
let net_event_response = NetworkEvent::HttpResponse(response);
|
||||
if let (Some(devtools_chan), Some(pipeline_id), Some(webview_id)) = (
|
||||
context.devtools_chan.as_ref(),
|
||||
request.pipeline_id,
|
||||
request.target_webview_id,
|
||||
) {
|
||||
let browsing_context_id = webview_id.0;
|
||||
let meta = match response
|
||||
.metadata()
|
||||
.expect("Response metadata should exist at this stage")
|
||||
{
|
||||
FetchMetadata::Unfiltered(m) => m,
|
||||
FetchMetadata::Filtered { unsafe_, .. } => unsafe_,
|
||||
};
|
||||
let status = meta.status;
|
||||
let headers = meta.headers.map(Serde::into_inner);
|
||||
|
||||
let msg = ChromeToDevtoolsControlMsg::NetworkEvent(request_id, net_event_response);
|
||||
let _ = devtools_chan.send(DevtoolsControlMsg::FromChrome(msg));
|
||||
let devtoolsresponse = DevtoolsHttpResponse {
|
||||
headers,
|
||||
status,
|
||||
body: None,
|
||||
pipeline_id,
|
||||
browsing_context_id,
|
||||
};
|
||||
let net_event_response = NetworkEvent::HttpResponse(devtoolsresponse);
|
||||
|
||||
let msg =
|
||||
ChromeToDevtoolsControlMsg::NetworkEvent(request.id.0.to_string(), net_event_response);
|
||||
|
||||
let _ = devtools_chan
|
||||
.lock()
|
||||
.unwrap()
|
||||
.send(DevtoolsControlMsg::FromChrome(msg));
|
||||
}
|
||||
}
|
||||
|
||||
pub fn send_early_httprequest_to_devtools(request: &mut Request, context: &FetchContext) {
|
||||
if let (Some(devtools_chan), Some(browsing_context_id), Some(pipeline_id)) = (
|
||||
context.devtools_chan.as_ref(),
|
||||
request.target_webview_id.map(|id| id.0),
|
||||
request.pipeline_id,
|
||||
) {
|
||||
// Build the partial DevtoolsHttpRequest
|
||||
let devtools_request = DevtoolsHttpRequest {
|
||||
url: request.current_url().clone(),
|
||||
method: request.method.clone(),
|
||||
headers: request.headers.clone(),
|
||||
body: None,
|
||||
pipeline_id,
|
||||
started_date_time: SystemTime::now(),
|
||||
time_stamp: 0,
|
||||
connect_time: Duration::from_millis(0),
|
||||
send_time: Duration::from_millis(0),
|
||||
is_xhr: false,
|
||||
browsing_context_id,
|
||||
};
|
||||
|
||||
let msg = ChromeToDevtoolsControlMsg::NetworkEvent(
|
||||
request.id.0.to_string(),
|
||||
NetworkEvent::HttpRequest(devtools_request),
|
||||
);
|
||||
|
||||
send_request_to_devtools(msg, &devtools_chan.lock().unwrap());
|
||||
}
|
||||
}
|
||||
|
||||
fn auth_from_cache(
|
||||
|
@ -885,6 +934,8 @@ pub async fn http_fetch(
|
|||
.try_code()
|
||||
.is_some_and(is_redirect_status)
|
||||
{
|
||||
// Notify devtools before handling redirect
|
||||
send_response_to_devtools(request, context, &response);
|
||||
// Substep 1.
|
||||
if response.actual_response().status != StatusCode::SEE_OTHER {
|
||||
// TODO: send RST_STREAM frame
|
||||
|
@ -1867,12 +1918,7 @@ async fn http_network_fetch(
|
|||
|
||||
// Step 5
|
||||
let url = request.current_url();
|
||||
|
||||
let request_id = context
|
||||
.devtools_chan
|
||||
.as_ref()
|
||||
.map(|_| uuid::Uuid::new_v4().simple().to_string());
|
||||
|
||||
let request_id = request.id.0.to_string();
|
||||
if log_enabled!(log::Level::Info) {
|
||||
info!("{:?} request for {}", request.method, url);
|
||||
for header in request.headers.iter() {
|
||||
|
@ -1912,14 +1958,13 @@ async fn http_network_fetch(
|
|||
.map(|body| body.source_is_null())
|
||||
.unwrap_or(false),
|
||||
&request.pipeline_id,
|
||||
request_id.as_deref(),
|
||||
Some(&request_id),
|
||||
is_xhr,
|
||||
context,
|
||||
fetch_terminated_sender,
|
||||
browsing_context_id,
|
||||
);
|
||||
|
||||
let pipeline_id = request.pipeline_id;
|
||||
// This will only get the headers, the body is read later
|
||||
let (res, msg) = match response_future.await {
|
||||
Ok(wrapped_response) => wrapped_response,
|
||||
|
@ -1995,17 +2040,8 @@ async fn http_network_fetch(
|
|||
// We're about to spawn a future to be waited on here
|
||||
let (done_sender, done_receiver) = unbounded_channel();
|
||||
*done_chan = Some((done_sender.clone(), done_receiver));
|
||||
let meta = match response
|
||||
.metadata()
|
||||
.expect("Response metadata should exist at this stage")
|
||||
{
|
||||
FetchMetadata::Unfiltered(m) => m,
|
||||
FetchMetadata::Filtered { unsafe_, .. } => unsafe_,
|
||||
};
|
||||
|
||||
let devtools_sender = context.devtools_chan.clone();
|
||||
let meta_status = meta.status;
|
||||
let meta_headers = meta.headers;
|
||||
let cancellation_listener = context.cancellation_listener.clone();
|
||||
if cancellation_listener.cancelled() {
|
||||
return Response::network_error(NetworkError::Internal("Fetch aborted".into()));
|
||||
|
@ -2019,19 +2055,6 @@ async fn http_network_fetch(
|
|||
if let Some(m) = msg {
|
||||
send_request_to_devtools(m, &sender);
|
||||
}
|
||||
|
||||
// --- Tell devtools that we got a response
|
||||
// Send an HttpResponse message to devtools with the corresponding request_id
|
||||
if let (Some(pipeline_id), Some(browsing_context_id)) = (pipeline_id, browsing_context_id) {
|
||||
send_response_to_devtools(
|
||||
&sender,
|
||||
request_id.unwrap(),
|
||||
meta_headers.map(Serde::into_inner),
|
||||
meta_status,
|
||||
pipeline_id,
|
||||
browsing_context_id,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
let done_sender2 = done_sender.clone();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue