Fix network event update Message (#37543)

- Add `ResourceArrayType` with `Available` and `Updated` variants
- Rename `resources-available` and `resource-available` to
`resources-array` ,`resource-array`
- Add `ResourceArrayType` as an argument to decide the type of resources
- Add `Option<ResponseContentMsg>`,`Option<ResponseStartMsg>`,
`Option<ResponseCookiesMsg>`,
`Option<ResponseHeadersMsg>`,`Option<RequestCookiesMsg>`,
`Option<RequestHeadersMsg>`, `total_time`, `security_state` to
`NetworkEventActor` struct , and serialize the data in each to
`resource_updates` , flattening the nested arrays into a single JSON
- Refactor the following methods `request_headers`,`response_start` ,
`response_content`,`response_cookies`,`response_headers`,
`request_cookies`,`total_time` to associated functions passing
`HttpRequest` and `HttpResponse` as parameters .

Testing: Ran servo with devtools flag to see the logs corresponding to
the changes
Fixes: https://github.com/servo/servo/issues/37479

This PR Builds on https://github.com/servo/servo/pull/37517 and was
opened due to merge conflicts and branch issues

---------

Signed-off-by: Uthman Yahaya Baba <uthmanyahayababa@gmail.com>
This commit is contained in:
Usman Yahaya Baba 2025-06-19 17:00:37 +01:00 committed by GitHub
parent 8edae71286
commit 7d2c9ec19c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 216 additions and 138 deletions

View file

@ -11,30 +11,8 @@ use serde::Serialize;
use crate::actor::ActorRegistry;
use crate::actors::browsing_context::BrowsingContextActor;
use crate::actors::network_event::NetworkEventActor;
use crate::resource::ResourceAvailable;
use crate::resource::{ResourceArrayType, ResourceAvailable};
#[derive(Clone, Serialize)]
struct ResourcesUpdatedArray {
updates: Vec<UpdateEntry>,
}
#[derive(Clone, Serialize)]
struct UpdateEntry {
#[serde(rename = "updateType")]
update_type: String,
data: serde_json::Value,
}
#[derive(Serialize)]
#[serde(rename_all = "camelCase")]
struct EventTimingsUpdateMsg {
total_time: u64,
}
#[derive(Serialize)]
struct SecurityInfoUpdateMsg {
state: String,
}
#[derive(Clone, Serialize)]
pub struct Cause {
#[serde(rename = "type")]
@ -63,9 +41,10 @@ pub(crate) fn handle_network_event(
let browsing_context_actor =
actors.find::<BrowsingContextActor>(&browsing_context_actor_name);
for stream in &mut connections {
browsing_context_actor.resource_available(
browsing_context_actor.resource_array(
event_actor.clone(),
"network-event".to_string(),
ResourceArrayType::Available,
stream,
);
}
@ -76,56 +55,16 @@ pub(crate) fn handle_network_event(
let actor = actors.find_mut::<NetworkEventActor>(&netevent_actor_name);
// Store the response information in the actor
actor.add_response(httpresponse);
ResourcesUpdatedArray {
updates: vec![
UpdateEntry {
update_type: "requestHeaders".to_owned(),
data: serde_json::to_value(actor.request_headers()).unwrap(),
},
UpdateEntry {
update_type: "requestCookies".to_owned(),
data: serde_json::to_value(actor.request_cookies()).unwrap(),
},
UpdateEntry {
update_type: "responseStart".to_owned(),
data: serde_json::to_value(actor.response_start()).unwrap(),
},
UpdateEntry {
update_type: "eventTimings".to_owned(),
data: serde_json::to_value(EventTimingsUpdateMsg {
total_time: actor.total_time().as_millis() as u64,
})
.unwrap(),
},
UpdateEntry {
update_type: "securityInfo".to_owned(),
data: serde_json::to_value(SecurityInfoUpdateMsg {
state: "insecure".to_owned(),
})
.unwrap(),
},
UpdateEntry {
update_type: "responseContent".to_owned(),
data: serde_json::to_value(actor.response_content()).unwrap(),
},
UpdateEntry {
update_type: "responseCookies".to_owned(),
data: serde_json::to_value(actor.response_cookies()).unwrap(),
},
UpdateEntry {
update_type: "responseHeaders".to_owned(),
data: serde_json::to_value(actor.response_headers()).unwrap(),
},
],
}
actor.resource_updates()
};
let browsing_context_actor =
actors.find::<BrowsingContextActor>(&browsing_context_actor_name);
for stream in &mut connections {
browsing_context_actor.resource_available(
browsing_context_actor.resource_array(
resource.clone(),
"resources-updated".to_string(),
"network-event".to_string(),
ResourceArrayType::Updated,
stream,
);
}