mirror of
https://github.com/servo/servo.git
synced 2025-07-19 21:33:49 +01:00
devtools: Use request destination as cause_type in NetworkEventActor (#38162)
The cause_type in NetworkEventActor was derived from a hard-coded pattern match on the request URL file extension. This patch replaces the hard-coded pattern matching with the Destination field of Request, to provide a better alignment with the Fetch specification. Testing: Updated unit tests. Fixes: #38151 --------- Signed-off-by: Kingsley Yung <kingsley@kkoyung.dev>
This commit is contained in:
parent
a52f9fd9a9
commit
0537c29064
5 changed files with 15 additions and 9 deletions
|
@ -11,6 +11,7 @@ use chrono::{Local, LocalResult, TimeZone};
|
||||||
use devtools_traits::{HttpRequest as DevtoolsHttpRequest, HttpResponse as DevtoolsHttpResponse};
|
use devtools_traits::{HttpRequest as DevtoolsHttpRequest, HttpResponse as DevtoolsHttpResponse};
|
||||||
use headers::{ContentType, Cookie, HeaderMapExt};
|
use headers::{ContentType, Cookie, HeaderMapExt};
|
||||||
use http::{HeaderMap, Method, header};
|
use http::{HeaderMap, Method, header};
|
||||||
|
use net_traits::request::Destination as RequestDestination;
|
||||||
use serde::Serialize;
|
use serde::Serialize;
|
||||||
use serde_json::{Map, Value};
|
use serde_json::{Map, Value};
|
||||||
|
|
||||||
|
@ -27,6 +28,7 @@ pub struct NetworkEventActor {
|
||||||
pub request_method: Method,
|
pub request_method: Method,
|
||||||
pub request_started: SystemTime,
|
pub request_started: SystemTime,
|
||||||
pub request_time_stamp: i64,
|
pub request_time_stamp: i64,
|
||||||
|
pub request_destination: RequestDestination,
|
||||||
pub request_headers_raw: Option<HeaderMap>,
|
pub request_headers_raw: Option<HeaderMap>,
|
||||||
pub request_body: Option<Vec<u8>>,
|
pub request_body: Option<Vec<u8>>,
|
||||||
pub request_cookies: Option<RequestCookiesMsg>,
|
pub request_cookies: Option<RequestCookiesMsg>,
|
||||||
|
@ -350,6 +352,7 @@ impl NetworkEventActor {
|
||||||
.duration_since(UNIX_EPOCH)
|
.duration_since(UNIX_EPOCH)
|
||||||
.unwrap_or_default()
|
.unwrap_or_default()
|
||||||
.as_secs() as i64,
|
.as_secs() as i64,
|
||||||
|
request_destination: RequestDestination::None,
|
||||||
request_headers_raw: None,
|
request_headers_raw: None,
|
||||||
request_body: None,
|
request_body: None,
|
||||||
request_cookies: None,
|
request_cookies: None,
|
||||||
|
@ -377,6 +380,7 @@ impl NetworkEventActor {
|
||||||
self.request_method = request.method;
|
self.request_method = request.method;
|
||||||
self.request_started = request.started_date_time;
|
self.request_started = request.started_date_time;
|
||||||
self.request_time_stamp = request.time_stamp;
|
self.request_time_stamp = request.time_stamp;
|
||||||
|
self.request_destination = request.destination;
|
||||||
self.request_body = request.body.clone();
|
self.request_body = request.body.clone();
|
||||||
self.request_headers_raw = Some(request.headers.clone());
|
self.request_headers_raw = Some(request.headers.clone());
|
||||||
}
|
}
|
||||||
|
@ -404,14 +408,6 @@ impl NetworkEventActor {
|
||||||
LocalResult::Ambiguous(date_time, _) => date_time.to_rfc3339().to_string(),
|
LocalResult::Ambiguous(date_time, _) => date_time.to_rfc3339().to_string(),
|
||||||
};
|
};
|
||||||
|
|
||||||
let cause_type = match self.request_url.as_str() {
|
|
||||||
// Adjust based on request data
|
|
||||||
url if url.ends_with(".css") => "stylesheet",
|
|
||||||
url if url.ends_with(".js") => "script",
|
|
||||||
url if url.ends_with(".png") || url.ends_with(".jpg") => "img",
|
|
||||||
_ => "document",
|
|
||||||
};
|
|
||||||
|
|
||||||
EventActor {
|
EventActor {
|
||||||
actor: self.name(),
|
actor: self.name(),
|
||||||
resource_id: self.resource_id,
|
resource_id: self.resource_id,
|
||||||
|
@ -422,7 +418,7 @@ impl NetworkEventActor {
|
||||||
is_xhr: self.is_xhr,
|
is_xhr: self.is_xhr,
|
||||||
private: false,
|
private: false,
|
||||||
cause: Cause {
|
cause: Cause {
|
||||||
type_: cause_type.to_string(),
|
type_: self.request_destination.as_str().to_string(),
|
||||||
loading_document_uri: None, // Set if available
|
loading_document_uri: None, // Set if available
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
|
@ -397,6 +397,7 @@ fn prepare_devtools_request(
|
||||||
pipeline_id: PipelineId,
|
pipeline_id: PipelineId,
|
||||||
connect_time: Duration,
|
connect_time: Duration,
|
||||||
send_time: Duration,
|
send_time: Duration,
|
||||||
|
destination: Destination,
|
||||||
is_xhr: bool,
|
is_xhr: bool,
|
||||||
browsing_context_id: BrowsingContextId,
|
browsing_context_id: BrowsingContextId,
|
||||||
) -> ChromeToDevtoolsControlMsg {
|
) -> ChromeToDevtoolsControlMsg {
|
||||||
|
@ -414,6 +415,7 @@ fn prepare_devtools_request(
|
||||||
.as_secs() as i64,
|
.as_secs() as i64,
|
||||||
connect_time,
|
connect_time,
|
||||||
send_time,
|
send_time,
|
||||||
|
destination,
|
||||||
is_xhr,
|
is_xhr,
|
||||||
browsing_context_id,
|
browsing_context_id,
|
||||||
};
|
};
|
||||||
|
@ -488,6 +490,7 @@ pub fn send_early_httprequest_to_devtools(request: &mut Request, context: &Fetch
|
||||||
time_stamp: 0,
|
time_stamp: 0,
|
||||||
connect_time: Duration::from_millis(0),
|
connect_time: Duration::from_millis(0),
|
||||||
send_time: Duration::from_millis(0),
|
send_time: Duration::from_millis(0),
|
||||||
|
destination: request.destination,
|
||||||
is_xhr: false,
|
is_xhr: false,
|
||||||
browsing_context_id,
|
browsing_context_id,
|
||||||
};
|
};
|
||||||
|
@ -586,6 +589,7 @@ async fn obtain_response(
|
||||||
source_is_null: bool,
|
source_is_null: bool,
|
||||||
pipeline_id: &Option<PipelineId>,
|
pipeline_id: &Option<PipelineId>,
|
||||||
request_id: Option<&str>,
|
request_id: Option<&str>,
|
||||||
|
destination: Destination,
|
||||||
is_xhr: bool,
|
is_xhr: bool,
|
||||||
context: &FetchContext,
|
context: &FetchContext,
|
||||||
fetch_terminated: UnboundedSender<bool>,
|
fetch_terminated: UnboundedSender<bool>,
|
||||||
|
@ -780,6 +784,7 @@ async fn obtain_response(
|
||||||
pipeline_id,
|
pipeline_id,
|
||||||
(connect_end - connect_start).unsigned_abs(),
|
(connect_end - connect_start).unsigned_abs(),
|
||||||
(send_end - send_start).unsigned_abs(),
|
(send_end - send_start).unsigned_abs(),
|
||||||
|
destination,
|
||||||
is_xhr,
|
is_xhr,
|
||||||
browsing_context_id,
|
browsing_context_id,
|
||||||
))
|
))
|
||||||
|
@ -1959,6 +1964,7 @@ async fn http_network_fetch(
|
||||||
.unwrap_or(false),
|
.unwrap_or(false),
|
||||||
&request.pipeline_id,
|
&request.pipeline_id,
|
||||||
Some(&request_id),
|
Some(&request_id),
|
||||||
|
request.destination,
|
||||||
is_xhr,
|
is_xhr,
|
||||||
context,
|
context,
|
||||||
fetch_terminated_sender,
|
fetch_terminated_sender,
|
||||||
|
|
|
@ -1339,6 +1339,7 @@ fn test_fetch_with_devtools() {
|
||||||
time_stamp: devhttprequests.1.time_stamp,
|
time_stamp: devhttprequests.1.time_stamp,
|
||||||
connect_time: devhttprequests.1.connect_time,
|
connect_time: devhttprequests.1.connect_time,
|
||||||
send_time: devhttprequests.1.send_time,
|
send_time: devhttprequests.1.send_time,
|
||||||
|
destination: Destination::None,
|
||||||
is_xhr: true,
|
is_xhr: true,
|
||||||
browsing_context_id: TEST_WEBVIEW_ID.0,
|
browsing_context_id: TEST_WEBVIEW_ID.0,
|
||||||
};
|
};
|
||||||
|
|
|
@ -333,6 +333,7 @@ fn test_request_and_response_data_with_network_messages() {
|
||||||
time_stamp: devhttprequests.1.time_stamp,
|
time_stamp: devhttprequests.1.time_stamp,
|
||||||
connect_time: devhttprequests.1.connect_time,
|
connect_time: devhttprequests.1.connect_time,
|
||||||
send_time: devhttprequests.1.send_time,
|
send_time: devhttprequests.1.send_time,
|
||||||
|
destination: Destination::Document,
|
||||||
is_xhr: false,
|
is_xhr: false,
|
||||||
browsing_context_id: TEST_WEBVIEW_ID.0,
|
browsing_context_id: TEST_WEBVIEW_ID.0,
|
||||||
};
|
};
|
||||||
|
|
|
@ -23,6 +23,7 @@ use http::{HeaderMap, Method};
|
||||||
use ipc_channel::ipc::IpcSender;
|
use ipc_channel::ipc::IpcSender;
|
||||||
use malloc_size_of_derive::MallocSizeOf;
|
use malloc_size_of_derive::MallocSizeOf;
|
||||||
use net_traits::http_status::HttpStatus;
|
use net_traits::http_status::HttpStatus;
|
||||||
|
use net_traits::request::Destination;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use servo_url::ServoUrl;
|
use servo_url::ServoUrl;
|
||||||
use uuid::Uuid;
|
use uuid::Uuid;
|
||||||
|
@ -443,6 +444,7 @@ pub struct HttpRequest {
|
||||||
pub time_stamp: i64,
|
pub time_stamp: i64,
|
||||||
pub connect_time: Duration,
|
pub connect_time: Duration,
|
||||||
pub send_time: Duration,
|
pub send_time: Duration,
|
||||||
|
pub destination: Destination,
|
||||||
pub is_xhr: bool,
|
pub is_xhr: bool,
|
||||||
pub browsing_context_id: BrowsingContextId,
|
pub browsing_context_id: BrowsingContextId,
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue