Calculate and send the missing transferred_size and content_size to dev tools (#38216)

The current behaviour in dev tools network monitor is missing data for
the `Transferred` size and `Content` size.
We currently have a fn `response_content` that constructs the
`ResponseContentMsg` struct where the two missing data fields are
defined and set to zero values.
These current changes calculates the data in the `response_content` fn
and sends a `NetworkEvent::HttpResponse` to the client when the final
body is done.
Currently, we have data appearing in the `Transferred` column of the
network panel
fixes: https://github.com/servo/servo/issues/38126

---------

Signed-off-by: uthmaniv <uthmanyahayababa@gmail.com>
This commit is contained in:
Usman Yahaya Baba 2025-08-02 11:41:53 +09:00 committed by GitHub
parent 52b04c9fd3
commit a27715a5a8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 98 additions and 33 deletions

View file

@ -662,7 +662,7 @@ pub async fn main_fetch(
let mut response_loaded = false;
let mut response = if !response.is_network_error() && !request.integrity_metadata.is_empty() {
// Step 19.1.
wait_for_response(request, &mut response, target, done_chan).await;
wait_for_response(request, &mut response, target, done_chan, context).await;
response_loaded = true;
// Step 19.2.
@ -686,7 +686,7 @@ pub async fn main_fetch(
// by sync fetch, but we overload it here for simplicity
target.process_response(request, &response);
if !response_loaded {
wait_for_response(request, &mut response, target, done_chan).await;
wait_for_response(request, &mut response, target, done_chan, context).await;
}
// overloaded similarly to process_response
target.process_response_eof(request, &response);
@ -706,11 +706,11 @@ pub async fn main_fetch(
// Step 22.
target.process_response(request, &response);
// Send Response to Devtools
send_response_to_devtools(request, context, &response);
send_response_to_devtools(request, context, &response, None);
// Step 23.
if !response_loaded {
wait_for_response(request, &mut response, target, done_chan).await;
wait_for_response(request, &mut response, target, done_chan, context).await;
}
// Step 24.
@ -718,7 +718,7 @@ pub async fn main_fetch(
// 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);
send_response_to_devtools(request, context, &response, None);
if let Ok(http_cache) = context.state.http_cache.write() {
http_cache.update_awaiting_consumers(request, &response);
@ -734,14 +734,20 @@ async fn wait_for_response(
response: &mut Response,
target: Target<'_>,
done_chan: &mut DoneChannel,
context: &FetchContext,
) {
if let Some(ref mut ch) = *done_chan {
let mut devtools_body = context.devtools_chan.as_ref().map(|_| Vec::new());
loop {
match ch.1.recv().await {
Some(Data::Payload(vec)) => {
if let Some(body) = devtools_body.as_mut() {
body.extend(&vec);
}
target.process_response_chunk(request, vec);
},
Some(Data::Done) => {
send_response_to_devtools(request, context, response, devtools_body);
break;
},
Some(Data::Cancelled) => {
@ -760,6 +766,11 @@ async fn wait_for_response(
// obtained synchronously via scheme_fetch for data/file/about/etc
// We should still send the body across as a chunk
target.process_response_chunk(request, vec.clone());
if context.devtools_chan.is_some() {
// Now that we've replayed the entire cached body,
// notify the DevTools server with the full Response.
send_response_to_devtools(request, context, response, Some(vec.clone()));
}
} else {
assert_eq!(*body, ResponseBody::Empty)
}