Skip to content

Commit 62216c8

Browse files
committed
Add addDataCollector, disownData, getData, removeDataCollector and setExtraHeaders network commands
1 parent 184277d commit 62216c8

File tree

6 files changed

+206
-8
lines changed

6 files changed

+206
-8
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "webdriverbidi"
3-
version = "0.2.1"
3+
version = "0.2.2"
44
edition = "2024"
55
authors = ["Taha Hachana <tahahachana@gmail.com>"]
66
description = "WebDriver BiDi client implementation in Rust."

README.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ Add the following to your `Cargo.toml` (the example below will also require toki
2323

2424
```toml
2525
[dependencies]
26-
webdriverbidi = "0.2.0"
26+
webdriverbidi = "0.2.2"
2727
```
2828

2929
### Usage
@@ -188,8 +188,11 @@ async fn main() -> Result<()> {
188188
- [x] network.AuthCredentials
189189
- [x] network.BaseParameters
190190
- [x] network.BytesValue
191+
- [x] network.Collector
192+
- [x] network.CollectorType
191193
- [x] network.Cookie
192194
- [x] network.CookieHeader
195+
- [x] network.DataType
193196
- [x] network.FetchTimingInfo
194197
- [x] network.Header
195198
- [x] network.Initiator
@@ -202,14 +205,19 @@ async fn main() -> Result<()> {
202205
- [x] network.UrlPattern
203206

204207
#### Commands
208+
- [x] network.addDataCollector
205209
- [x] network.addIntercept
206210
- [x] network.continueRequest
207211
- [x] network.continueResponse
208212
- [x] network.continueWithAuth
213+
- [x] The network.disownData
209214
- [x] network.failRequest
215+
- [x] network.getData
210216
- [x] network.provideResponse
217+
- [x] network.removeDataCollector
211218
- [x] network.removeIntercept
212219
- [x] network.setCacheBehavior
220+
- [x] network.setExtraHeaders
213221

214222
#### Events
215223
- [x] network.authRequired

src/commands/network.rs

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,15 @@ use crate::model::network::*;
88
use crate::model::result::EmptyResult;
99
use crate::session::WebDriverBiDiSession;
1010

11+
// https://w3c.github.io/webdriver-bidi/#command-network-addDataCollector
12+
define_command!(
13+
AddDataCollectorCommand,
14+
AddDataCollector,
15+
AddDataCollectorParameters,
16+
add_data_collector,
17+
AddDataCollectorResult
18+
);
19+
1120
// https://w3c.github.io/webdriver-bidi/#command-network-addIntercept
1221
define_command!(
1322
AddInterceptCommand,
@@ -44,6 +53,15 @@ define_command!(
4453
EmptyResult
4554
);
4655

56+
// https://w3c.github.io/webdriver-bidi/#command-network-disownData
57+
define_command!(
58+
DisownDataCommand,
59+
DisownData,
60+
DisownDataParameters,
61+
disown_data,
62+
EmptyResult
63+
);
64+
4765
// https://w3c.github.io/webdriver-bidi/#command-network-failRequest
4866
define_command!(
4967
FailRequestCommand,
@@ -53,6 +71,15 @@ define_command!(
5371
EmptyResult
5472
);
5573

74+
// https://w3c.github.io/webdriver-bidi/#command-network-getData
75+
define_command!(
76+
GetDataCommand,
77+
GetData,
78+
GetDataParameters,
79+
get_data,
80+
GetDataResult
81+
);
82+
5683
// https://w3c.github.io/webdriver-bidi/#command-network-provideResponse
5784
define_command!(
5885
ProvideResponseCommand,
@@ -62,6 +89,15 @@ define_command!(
6289
EmptyResult
6390
);
6491

92+
// https://w3c.github.io/webdriver-bidi/#command-network-removeDataCollector
93+
define_command!(
94+
RemoveDataCollectorCommand,
95+
RemoveDataCollector,
96+
RemoveDataCollectorParameters,
97+
remove_data_collector,
98+
EmptyResult
99+
);
100+
65101
// https://w3c.github.io/webdriver-bidi/#command-network-removeIntercept
66102
define_command!(
67103
RemoveInterceptCommand,
@@ -79,3 +115,12 @@ define_command!(
79115
set_cache_behavior,
80116
EmptyResult
81117
);
118+
119+
// https://w3c.github.io/webdriver-bidi/#command-network-setExtraHeaders
120+
define_command!(
121+
SetExtraHeadersCommand,
122+
SetExtraHeaders,
123+
SetExtraHeadersParameters,
124+
set_extra_headers,
125+
EmptyResult
126+
);

src/model/network.rs

Lines changed: 60 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,15 @@ pub struct AddDataCollector {
351351
pub params: AddDataCollectorParameters,
352352
}
353353

354+
impl AddDataCollector {
355+
pub fn new(params: AddDataCollectorParameters) -> Self {
356+
Self {
357+
method: "network.addDataCollector".to_string(),
358+
params,
359+
}
360+
}
361+
}
362+
354363
#[derive(Debug, Serialize, Deserialize)]
355364
pub struct AddDataCollectorParameters {
356365
#[serde(rename = "dataTypes")]
@@ -604,6 +613,15 @@ pub struct DisownData {
604613
pub params: DisownDataParameters,
605614
}
606615

616+
impl DisownData {
617+
pub fn new(params: DisownDataParameters) -> Self {
618+
Self {
619+
method: "network.disownData".to_string(),
620+
params,
621+
}
622+
}
623+
}
624+
607625
#[derive(Debug, Serialize, Deserialize)]
608626
pub struct DisownDataParameters {
609627
#[serde(rename = "dataType")]
@@ -644,6 +662,15 @@ pub struct GetData {
644662
pub params: GetDataParameters,
645663
}
646664

665+
impl GetData {
666+
pub fn new(params: GetDataParameters) -> Self {
667+
Self {
668+
method: "network.getData".to_string(),
669+
params,
670+
}
671+
}
672+
}
673+
647674
#[derive(Debug, Serialize, Deserialize)]
648675
pub struct GetDataParameters {
649676
#[serde(rename = "dataType")]
@@ -710,17 +737,21 @@ impl ProvideResponseParameters {
710737
}
711738
}
712739

713-
// network.RemoveDataCollector = (
714-
// method: "network.removeDataCollector",
715-
// params: network.RemoveDataCollectorParameters
716-
// )
717-
718740
#[derive(Debug, Serialize, Deserialize)]
719741
pub struct RemoveDataCollector {
720742
pub method: String,
721743
pub params: RemoveDataCollectorParameters,
722744
}
723745

746+
impl RemoveDataCollector {
747+
pub fn new(params: RemoveDataCollectorParameters) -> Self {
748+
Self {
749+
method: "network.removeDataCollector".to_string(),
750+
params,
751+
}
752+
}
753+
}
754+
724755
#[derive(Debug, Serialize, Deserialize)]
725756
pub struct RemoveDataCollectorParameters {
726757
pub collector: Collector,
@@ -856,3 +887,27 @@ pub struct ResponseStartedParameters {
856887
pub base: BaseParameters,
857888
pub response: ResponseData,
858889
}
890+
891+
#[derive(Debug, Serialize, Deserialize)]
892+
pub struct SetExtraHeaders {
893+
pub method: String,
894+
pub params: SetExtraHeadersParameters,
895+
}
896+
897+
impl SetExtraHeaders {
898+
pub fn new(params: SetExtraHeadersParameters) -> Self {
899+
Self {
900+
method: "network.setExtraHeaders".to_string(),
901+
params,
902+
}
903+
}
904+
}
905+
906+
#[derive(Debug, Serialize, Deserialize)]
907+
pub struct SetExtraHeadersParameters {
908+
pub headers: Vec<Header>,
909+
#[serde(skip_serializing_if = "Option::is_none")]
910+
pub contexts: Option<Vec<BrowsingContext>>,
911+
#[serde(rename = "userContexts", skip_serializing_if = "Option::is_none")]
912+
pub user_contexts: Option<Vec<UserContext>>,
913+
}

src/session.rs

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -700,6 +700,24 @@ impl WebDriverBiDiSession {
700700

701701
// Network commands
702702
impl WebDriverBiDiSession {
703+
// https://w3c.github.io/webdriver-bidi/#command-network-addDataCollector
704+
705+
/// Add a data collector.
706+
///
707+
/// # Arguments
708+
///
709+
/// * `params` - The parameters as an `AddDataCollectorParameters` instance.
710+
///
711+
/// # Returns
712+
///
713+
/// A result containing the `AddDataCollectorResult` or a `CommandError`.
714+
pub async fn network_add_data_collector(
715+
&mut self,
716+
params: AddDataCollectorParameters,
717+
) -> Result<AddDataCollectorResult, CommandError> {
718+
commands::network::add_data_collector(self, params).await
719+
}
720+
703721
// https://w3c.github.io/webdriver-bidi/#command-network-addIntercept
704722

705723
/// Add a network intercept.
@@ -772,6 +790,24 @@ impl WebDriverBiDiSession {
772790
commands::network::continue_with_auth(self, params).await
773791
}
774792

793+
// https://w3c.github.io/webdriver-bidi/#command-network-disownData
794+
795+
/// Release a collected network data for a given collector.
796+
///
797+
/// # Arguments
798+
///
799+
/// * `params` - The parameters as a `DisownDataParameters` instance.
800+
///
801+
/// # Returns
802+
///
803+
/// A result containing the `EmptyResult` or a `CommandError`.
804+
pub async fn network_disown_data(
805+
&mut self,
806+
params: DisownDataParameters,
807+
) -> Result<EmptyResult, CommandError> {
808+
commands::network::disown_data(self, params).await
809+
}
810+
775811
// https://w3c.github.io/webdriver-bidi/#command-network-failRequest
776812

777813
/// Fail a fetch that’s blocked by a network intercept.
@@ -790,6 +826,24 @@ impl WebDriverBiDiSession {
790826
commands::network::fail_request(self, params).await
791827
}
792828

829+
// https://w3c.github.io/webdriver-bidi/#command-network-getData
830+
831+
/// Retrieve a network data if it is available.
832+
///
833+
/// # Arguments
834+
///
835+
/// * `params` - The parameters as a `GetDataParameters` instance.
836+
///
837+
/// # Returns
838+
///
839+
/// A result containing the `GetDataResult` or a `CommandError`.
840+
pub async fn network_get_data(
841+
&mut self,
842+
params: GetDataParameters,
843+
) -> Result<GetDataResult, CommandError> {
844+
commands::network::get_data(self, params).await
845+
}
846+
793847
// https://w3c.github.io/webdriver-bidi/#command-network-provideResponse
794848

795849
/// Continue a request that’s blocked by a network intercept, by providing a complete response.
@@ -808,6 +862,24 @@ impl WebDriverBiDiSession {
808862
commands::network::provide_response(self, params).await
809863
}
810864

865+
// https://w3c.github.io/webdriver-bidi/#command-network-removeDataCollector
866+
867+
/// Remove a data collector.
868+
///
869+
/// # Arguments
870+
///
871+
/// * `params` - The parameters as an `RemoveDataCollectorParameters` instance.
872+
///
873+
/// # Returns
874+
///
875+
/// A result containing the `EmptyResult` or a `CommandError`.
876+
pub async fn network_remove_data_collector(
877+
&mut self,
878+
params: RemoveDataCollectorParameters,
879+
) -> Result<EmptyResult, CommandError> {
880+
commands::network::remove_data_collector(self, params).await
881+
}
882+
811883
// https://w3c.github.io/webdriver-bidi/#command-network-removeIntercept
812884

813885
/// Remove a network intercept.
@@ -843,6 +915,24 @@ impl WebDriverBiDiSession {
843915
) -> Result<EmptyResult, CommandError> {
844916
commands::network::set_cache_behavior(self, params).await
845917
}
918+
919+
// https://w3c.github.io/webdriver-bidi/#command-network-setExtraHeaders
920+
921+
/// Allow specifying headers that will extend, or overwrite, existing request headers.
922+
///
923+
/// # Arguments
924+
///
925+
/// * `params` - The parameters as a `SetExtraHeadersParameters` instance.
926+
///
927+
/// # Returns
928+
///
929+
/// A result containing the `EmptyResult` or a `CommandError`.
930+
pub async fn network_set_extra_headers(
931+
&mut self,
932+
params: SetExtraHeadersParameters,
933+
) -> Result<EmptyResult, CommandError> {
934+
commands::network::set_extra_headers(self, params).await
935+
}
846936
}
847937

848938
// Script commands

0 commit comments

Comments
 (0)