servo/components/devtools/resource.rs
Usman Yahaya Baba 7d2c9ec19c
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>
2025-06-19 16:00:37 +00:00

55 lines
1.5 KiB
Rust

/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
use std::net::TcpStream;
use serde::Serialize;
use crate::protocol::JsonPacketStream;
pub enum ResourceArrayType {
Available,
Updated,
}
#[derive(Serialize)]
pub(crate) struct ResourceAvailableReply<T: Serialize> {
pub from: String,
#[serde(rename = "type")]
pub type_: String,
pub array: Vec<(String, Vec<T>)>,
}
pub(crate) trait ResourceAvailable {
fn actor_name(&self) -> String;
fn resource_array<T: Serialize>(
&self,
resource: T,
resource_type: String,
array_type: ResourceArrayType,
stream: &mut TcpStream,
) {
self.resources_array(vec![resource], resource_type, array_type, stream);
}
fn resources_array<T: Serialize>(
&self,
resources: Vec<T>,
resource_type: String,
array_type: ResourceArrayType,
stream: &mut TcpStream,
) {
let msg = ResourceAvailableReply::<T> {
from: self.actor_name(),
type_: match array_type {
ResourceArrayType::Available => "resources-available-array".to_string(),
ResourceArrayType::Updated => "resources-updated-array".to_string(),
},
array: vec![(resource_type, resources)],
};
let _ = stream.write_json_packet(&msg);
}
}