Skip to main content

browser_protocol/fetch/
mod.rs

1//! A domain for letting clients substitute browser's network layer with client code.
2
3
4use serde::{Serialize, Deserialize};
5use serde_json::Value as JsonValue;
6use std::borrow::Cow;
7
8/// Unique request identifier.
9/// Note that this does not identify individual HTTP requests that are part of
10/// a network request.
11
12pub type RequestId<'a> = Cow<'a, str>;
13
14/// Stages of the request to handle. Request will intercept before the request is
15/// sent. Response will intercept after the response is received (but before response
16/// body is received).
17
18#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Default)]
19pub enum RequestStage {
20    #[default]
21    #[serde(rename = "Request")]
22    Request,
23    #[serde(rename = "Response")]
24    Response,
25}
26
27
28#[derive(Debug, Clone, Serialize, Deserialize, Default)]
29#[serde(rename_all = "camelCase")]
30pub struct RequestPattern<'a> {
31    /// Wildcards (''*'' -\> zero or more, ''?'' -\> exactly one) are allowed. Escape character is
32    /// backslash. Omitting is equivalent to '"*"'.
33    #[serde(skip_serializing_if = "Option::is_none", rename = "urlPattern")]
34    url_pattern: Option<Cow<'a, str>>,
35    /// If set, only requests for matching resource types will be intercepted.
36    #[serde(skip_serializing_if = "Option::is_none", rename = "resourceType")]
37    resource_type: Option<crate::network::ResourceType>,
38    /// Stage at which to begin intercepting requests. Default is Request.
39    #[serde(skip_serializing_if = "Option::is_none", rename = "requestStage")]
40    request_stage: Option<RequestStage>,
41}
42
43impl<'a> RequestPattern<'a> {
44    /// Creates a builder for this type.
45    pub fn builder() -> RequestPatternBuilder<'a> {
46        RequestPatternBuilder {
47            url_pattern: None,
48            resource_type: None,
49            request_stage: None,
50        }
51    }
52    /// Wildcards (''*'' -\> zero or more, ''?'' -\> exactly one) are allowed. Escape character is
53    /// backslash. Omitting is equivalent to '"*"'.
54    pub fn url_pattern(&self) -> Option<&str> { self.url_pattern.as_deref() }
55    /// If set, only requests for matching resource types will be intercepted.
56    pub fn resource_type(&self) -> Option<&crate::network::ResourceType> { self.resource_type.as_ref() }
57    /// Stage at which to begin intercepting requests. Default is Request.
58    pub fn request_stage(&self) -> Option<&RequestStage> { self.request_stage.as_ref() }
59}
60
61#[derive(Default)]
62pub struct RequestPatternBuilder<'a> {
63    url_pattern: Option<Cow<'a, str>>,
64    resource_type: Option<crate::network::ResourceType>,
65    request_stage: Option<RequestStage>,
66}
67
68impl<'a> RequestPatternBuilder<'a> {
69    /// Wildcards (''*'' -\> zero or more, ''?'' -\> exactly one) are allowed. Escape character is
70    /// backslash. Omitting is equivalent to '"*"'.
71    pub fn url_pattern(mut self, url_pattern: impl Into<Cow<'a, str>>) -> Self { self.url_pattern = Some(url_pattern.into()); self }
72    /// If set, only requests for matching resource types will be intercepted.
73    pub fn resource_type(mut self, resource_type: crate::network::ResourceType) -> Self { self.resource_type = Some(resource_type); self }
74    /// Stage at which to begin intercepting requests. Default is Request.
75    pub fn request_stage(mut self, request_stage: impl Into<RequestStage>) -> Self { self.request_stage = Some(request_stage.into()); self }
76    pub fn build(self) -> RequestPattern<'a> {
77        RequestPattern {
78            url_pattern: self.url_pattern,
79            resource_type: self.resource_type,
80            request_stage: self.request_stage,
81        }
82    }
83}
84
85/// Response HTTP header entry
86
87#[derive(Debug, Clone, Serialize, Deserialize, Default)]
88#[serde(rename_all = "camelCase")]
89pub struct HeaderEntry<'a> {
90    name: Cow<'a, str>,
91    value: Cow<'a, str>,
92}
93
94impl<'a> HeaderEntry<'a> {
95    /// Creates a builder for this type with the required parameters:
96    /// * `name`: 
97    /// * `value`: 
98    pub fn builder(name: impl Into<Cow<'a, str>>, value: impl Into<Cow<'a, str>>) -> HeaderEntryBuilder<'a> {
99        HeaderEntryBuilder {
100            name: name.into(),
101            value: value.into(),
102        }
103    }
104    pub fn name(&self) -> &str { self.name.as_ref() }
105    pub fn value(&self) -> &str { self.value.as_ref() }
106}
107
108
109pub struct HeaderEntryBuilder<'a> {
110    name: Cow<'a, str>,
111    value: Cow<'a, str>,
112}
113
114impl<'a> HeaderEntryBuilder<'a> {
115    pub fn build(self) -> HeaderEntry<'a> {
116        HeaderEntry {
117            name: self.name,
118            value: self.value,
119        }
120    }
121}
122
123/// Authorization challenge for HTTP status code 401 or 407.
124
125#[derive(Debug, Clone, Serialize, Deserialize, Default)]
126#[serde(rename_all = "camelCase")]
127pub struct AuthChallenge<'a> {
128    /// Source of the authentication challenge.
129    #[serde(skip_serializing_if = "Option::is_none")]
130    source: Option<Cow<'a, str>>,
131    /// Origin of the challenger.
132    origin: Cow<'a, str>,
133    /// The authentication scheme used, such as basic or digest
134    scheme: Cow<'a, str>,
135    /// The realm of the challenge. May be empty.
136    realm: Cow<'a, str>,
137}
138
139impl<'a> AuthChallenge<'a> {
140    /// Creates a builder for this type with the required parameters:
141    /// * `origin`: Origin of the challenger.
142    /// * `scheme`: The authentication scheme used, such as basic or digest
143    /// * `realm`: The realm of the challenge. May be empty.
144    pub fn builder(origin: impl Into<Cow<'a, str>>, scheme: impl Into<Cow<'a, str>>, realm: impl Into<Cow<'a, str>>) -> AuthChallengeBuilder<'a> {
145        AuthChallengeBuilder {
146            source: None,
147            origin: origin.into(),
148            scheme: scheme.into(),
149            realm: realm.into(),
150        }
151    }
152    /// Source of the authentication challenge.
153    pub fn source(&self) -> Option<&str> { self.source.as_deref() }
154    /// Origin of the challenger.
155    pub fn origin(&self) -> &str { self.origin.as_ref() }
156    /// The authentication scheme used, such as basic or digest
157    pub fn scheme(&self) -> &str { self.scheme.as_ref() }
158    /// The realm of the challenge. May be empty.
159    pub fn realm(&self) -> &str { self.realm.as_ref() }
160}
161
162
163pub struct AuthChallengeBuilder<'a> {
164    source: Option<Cow<'a, str>>,
165    origin: Cow<'a, str>,
166    scheme: Cow<'a, str>,
167    realm: Cow<'a, str>,
168}
169
170impl<'a> AuthChallengeBuilder<'a> {
171    /// Source of the authentication challenge.
172    pub fn source(mut self, source: impl Into<Cow<'a, str>>) -> Self { self.source = Some(source.into()); self }
173    pub fn build(self) -> AuthChallenge<'a> {
174        AuthChallenge {
175            source: self.source,
176            origin: self.origin,
177            scheme: self.scheme,
178            realm: self.realm,
179        }
180    }
181}
182
183/// Response to an AuthChallenge.
184
185#[derive(Debug, Clone, Serialize, Deserialize, Default)]
186#[serde(rename_all = "camelCase")]
187pub struct AuthChallengeResponse<'a> {
188    /// The decision on what to do in response to the authorization challenge.  Default means
189    /// deferring to the default behavior of the net stack, which will likely either the Cancel
190    /// authentication or display a popup dialog box.
191    response: Cow<'a, str>,
192    /// The username to provide, possibly empty. Should only be set if response is
193    /// ProvideCredentials.
194    #[serde(skip_serializing_if = "Option::is_none")]
195    username: Option<Cow<'a, str>>,
196    /// The password to provide, possibly empty. Should only be set if response is
197    /// ProvideCredentials.
198    #[serde(skip_serializing_if = "Option::is_none")]
199    password: Option<Cow<'a, str>>,
200}
201
202impl<'a> AuthChallengeResponse<'a> {
203    /// Creates a builder for this type with the required parameters:
204    /// * `response`: The decision on what to do in response to the authorization challenge.  Default means deferring to the default behavior of the net stack, which will likely either the Cancel authentication or display a popup dialog box.
205    pub fn builder(response: impl Into<Cow<'a, str>>) -> AuthChallengeResponseBuilder<'a> {
206        AuthChallengeResponseBuilder {
207            response: response.into(),
208            username: None,
209            password: None,
210        }
211    }
212    /// The decision on what to do in response to the authorization challenge.  Default means
213    /// deferring to the default behavior of the net stack, which will likely either the Cancel
214    /// authentication or display a popup dialog box.
215    pub fn response(&self) -> &str { self.response.as_ref() }
216    /// The username to provide, possibly empty. Should only be set if response is
217    /// ProvideCredentials.
218    pub fn username(&self) -> Option<&str> { self.username.as_deref() }
219    /// The password to provide, possibly empty. Should only be set if response is
220    /// ProvideCredentials.
221    pub fn password(&self) -> Option<&str> { self.password.as_deref() }
222}
223
224
225pub struct AuthChallengeResponseBuilder<'a> {
226    response: Cow<'a, str>,
227    username: Option<Cow<'a, str>>,
228    password: Option<Cow<'a, str>>,
229}
230
231impl<'a> AuthChallengeResponseBuilder<'a> {
232    /// The username to provide, possibly empty. Should only be set if response is
233    /// ProvideCredentials.
234    pub fn username(mut self, username: impl Into<Cow<'a, str>>) -> Self { self.username = Some(username.into()); self }
235    /// The password to provide, possibly empty. Should only be set if response is
236    /// ProvideCredentials.
237    pub fn password(mut self, password: impl Into<Cow<'a, str>>) -> Self { self.password = Some(password.into()); self }
238    pub fn build(self) -> AuthChallengeResponse<'a> {
239        AuthChallengeResponse {
240            response: self.response,
241            username: self.username,
242            password: self.password,
243        }
244    }
245}
246
247#[derive(Debug, Clone, Serialize, Deserialize, Default)]
248pub struct DisableParams {}
249
250impl DisableParams { pub const METHOD: &'static str = "Fetch.disable"; }
251
252impl<'a> crate::CdpCommand<'a> for DisableParams {
253    const METHOD: &'static str = "Fetch.disable";
254    type Response = crate::EmptyReturns;
255}
256
257/// Enables issuing of requestPaused events. A request will be paused until client
258/// calls one of failRequest, fulfillRequest or continueRequest/continueWithAuth.
259
260#[derive(Debug, Clone, Serialize, Deserialize, Default)]
261#[serde(rename_all = "camelCase")]
262pub struct EnableParams<'a> {
263    /// If specified, only requests matching any of these patterns will produce
264    /// fetchRequested event and will be paused until clients response. If not set,
265    /// all requests will be affected.
266    #[serde(skip_serializing_if = "Option::is_none")]
267    patterns: Option<Vec<RequestPattern<'a>>>,
268    /// If true, authRequired events will be issued and requests will be paused
269    /// expecting a call to continueWithAuth.
270    #[serde(skip_serializing_if = "Option::is_none", rename = "handleAuthRequests")]
271    handle_auth_requests: Option<bool>,
272}
273
274impl<'a> EnableParams<'a> {
275    /// Creates a builder for this type.
276    pub fn builder() -> EnableParamsBuilder<'a> {
277        EnableParamsBuilder {
278            patterns: None,
279            handle_auth_requests: None,
280        }
281    }
282    /// If specified, only requests matching any of these patterns will produce
283    /// fetchRequested event and will be paused until clients response. If not set,
284    /// all requests will be affected.
285    pub fn patterns(&self) -> Option<&[RequestPattern<'a>]> { self.patterns.as_deref() }
286    /// If true, authRequired events will be issued and requests will be paused
287    /// expecting a call to continueWithAuth.
288    pub fn handle_auth_requests(&self) -> Option<bool> { self.handle_auth_requests }
289}
290
291#[derive(Default)]
292pub struct EnableParamsBuilder<'a> {
293    patterns: Option<Vec<RequestPattern<'a>>>,
294    handle_auth_requests: Option<bool>,
295}
296
297impl<'a> EnableParamsBuilder<'a> {
298    /// If specified, only requests matching any of these patterns will produce
299    /// fetchRequested event and will be paused until clients response. If not set,
300    /// all requests will be affected.
301    pub fn patterns(mut self, patterns: Vec<RequestPattern<'a>>) -> Self { self.patterns = Some(patterns); self }
302    /// If true, authRequired events will be issued and requests will be paused
303    /// expecting a call to continueWithAuth.
304    pub fn handle_auth_requests(mut self, handle_auth_requests: bool) -> Self { self.handle_auth_requests = Some(handle_auth_requests); self }
305    pub fn build(self) -> EnableParams<'a> {
306        EnableParams {
307            patterns: self.patterns,
308            handle_auth_requests: self.handle_auth_requests,
309        }
310    }
311}
312
313impl<'a> EnableParams<'a> { pub const METHOD: &'static str = "Fetch.enable"; }
314
315impl<'a> crate::CdpCommand<'a> for EnableParams<'a> {
316    const METHOD: &'static str = "Fetch.enable";
317    type Response = crate::EmptyReturns;
318}
319
320/// Causes the request to fail with specified reason.
321
322#[derive(Debug, Clone, Serialize, Deserialize, Default)]
323#[serde(rename_all = "camelCase")]
324pub struct FailRequestParams<'a> {
325    /// An id the client received in requestPaused event.
326    #[serde(rename = "requestId")]
327    request_id: RequestId<'a>,
328    /// Causes the request to fail with the given reason.
329    #[serde(rename = "errorReason")]
330    error_reason: crate::network::ErrorReason,
331}
332
333impl<'a> FailRequestParams<'a> {
334    /// Creates a builder for this type with the required parameters:
335    /// * `request_id`: An id the client received in requestPaused event.
336    /// * `error_reason`: Causes the request to fail with the given reason.
337    pub fn builder(request_id: impl Into<RequestId<'a>>, error_reason: crate::network::ErrorReason) -> FailRequestParamsBuilder<'a> {
338        FailRequestParamsBuilder {
339            request_id: request_id.into(),
340            error_reason: error_reason,
341        }
342    }
343    /// An id the client received in requestPaused event.
344    pub fn request_id(&self) -> &RequestId<'a> { &self.request_id }
345    /// Causes the request to fail with the given reason.
346    pub fn error_reason(&self) -> &crate::network::ErrorReason { &self.error_reason }
347}
348
349
350pub struct FailRequestParamsBuilder<'a> {
351    request_id: RequestId<'a>,
352    error_reason: crate::network::ErrorReason,
353}
354
355impl<'a> FailRequestParamsBuilder<'a> {
356    pub fn build(self) -> FailRequestParams<'a> {
357        FailRequestParams {
358            request_id: self.request_id,
359            error_reason: self.error_reason,
360        }
361    }
362}
363
364impl<'a> FailRequestParams<'a> { pub const METHOD: &'static str = "Fetch.failRequest"; }
365
366impl<'a> crate::CdpCommand<'a> for FailRequestParams<'a> {
367    const METHOD: &'static str = "Fetch.failRequest";
368    type Response = crate::EmptyReturns;
369}
370
371/// Provides response to the request.
372
373#[derive(Debug, Clone, Serialize, Deserialize, Default)]
374#[serde(rename_all = "camelCase")]
375pub struct FulfillRequestParams<'a> {
376    /// An id the client received in requestPaused event.
377    #[serde(rename = "requestId")]
378    request_id: RequestId<'a>,
379    /// An HTTP response code.
380    #[serde(rename = "responseCode")]
381    response_code: i64,
382    /// Response headers.
383    #[serde(skip_serializing_if = "Option::is_none", rename = "responseHeaders")]
384    response_headers: Option<Vec<HeaderEntry<'a>>>,
385    /// Alternative way of specifying response headers as a \0-separated
386    /// series of name: value pairs. Prefer the above method unless you
387    /// need to represent some non-UTF8 values that can't be transmitted
388    /// over the protocol as text. (Encoded as a base64 string when passed over JSON)
389    #[serde(skip_serializing_if = "Option::is_none", rename = "binaryResponseHeaders")]
390    binary_response_headers: Option<Cow<'a, str>>,
391    /// A response body. If absent, original response body will be used if
392    /// the request is intercepted at the response stage and empty body
393    /// will be used if the request is intercepted at the request stage. (Encoded as a base64 string when passed over JSON)
394    #[serde(skip_serializing_if = "Option::is_none")]
395    body: Option<Cow<'a, str>>,
396    /// A textual representation of responseCode.
397    /// If absent, a standard phrase matching responseCode is used.
398    #[serde(skip_serializing_if = "Option::is_none", rename = "responsePhrase")]
399    response_phrase: Option<Cow<'a, str>>,
400}
401
402impl<'a> FulfillRequestParams<'a> {
403    /// Creates a builder for this type with the required parameters:
404    /// * `request_id`: An id the client received in requestPaused event.
405    /// * `response_code`: An HTTP response code.
406    pub fn builder(request_id: impl Into<RequestId<'a>>, response_code: i64) -> FulfillRequestParamsBuilder<'a> {
407        FulfillRequestParamsBuilder {
408            request_id: request_id.into(),
409            response_code: response_code,
410            response_headers: None,
411            binary_response_headers: None,
412            body: None,
413            response_phrase: None,
414        }
415    }
416    /// An id the client received in requestPaused event.
417    pub fn request_id(&self) -> &RequestId<'a> { &self.request_id }
418    /// An HTTP response code.
419    pub fn response_code(&self) -> i64 { self.response_code }
420    /// Response headers.
421    pub fn response_headers(&self) -> Option<&[HeaderEntry<'a>]> { self.response_headers.as_deref() }
422    /// Alternative way of specifying response headers as a \0-separated
423    /// series of name: value pairs. Prefer the above method unless you
424    /// need to represent some non-UTF8 values that can't be transmitted
425    /// over the protocol as text. (Encoded as a base64 string when passed over JSON)
426    pub fn binary_response_headers(&self) -> Option<&str> { self.binary_response_headers.as_deref() }
427    /// A response body. If absent, original response body will be used if
428    /// the request is intercepted at the response stage and empty body
429    /// will be used if the request is intercepted at the request stage. (Encoded as a base64 string when passed over JSON)
430    pub fn body(&self) -> Option<&str> { self.body.as_deref() }
431    /// A textual representation of responseCode.
432    /// If absent, a standard phrase matching responseCode is used.
433    pub fn response_phrase(&self) -> Option<&str> { self.response_phrase.as_deref() }
434}
435
436
437pub struct FulfillRequestParamsBuilder<'a> {
438    request_id: RequestId<'a>,
439    response_code: i64,
440    response_headers: Option<Vec<HeaderEntry<'a>>>,
441    binary_response_headers: Option<Cow<'a, str>>,
442    body: Option<Cow<'a, str>>,
443    response_phrase: Option<Cow<'a, str>>,
444}
445
446impl<'a> FulfillRequestParamsBuilder<'a> {
447    /// Response headers.
448    pub fn response_headers(mut self, response_headers: Vec<HeaderEntry<'a>>) -> Self { self.response_headers = Some(response_headers); self }
449    /// Alternative way of specifying response headers as a \0-separated
450    /// series of name: value pairs. Prefer the above method unless you
451    /// need to represent some non-UTF8 values that can't be transmitted
452    /// over the protocol as text. (Encoded as a base64 string when passed over JSON)
453    pub fn binary_response_headers(mut self, binary_response_headers: impl Into<Cow<'a, str>>) -> Self { self.binary_response_headers = Some(binary_response_headers.into()); self }
454    /// A response body. If absent, original response body will be used if
455    /// the request is intercepted at the response stage and empty body
456    /// will be used if the request is intercepted at the request stage. (Encoded as a base64 string when passed over JSON)
457    pub fn body(mut self, body: impl Into<Cow<'a, str>>) -> Self { self.body = Some(body.into()); self }
458    /// A textual representation of responseCode.
459    /// If absent, a standard phrase matching responseCode is used.
460    pub fn response_phrase(mut self, response_phrase: impl Into<Cow<'a, str>>) -> Self { self.response_phrase = Some(response_phrase.into()); self }
461    pub fn build(self) -> FulfillRequestParams<'a> {
462        FulfillRequestParams {
463            request_id: self.request_id,
464            response_code: self.response_code,
465            response_headers: self.response_headers,
466            binary_response_headers: self.binary_response_headers,
467            body: self.body,
468            response_phrase: self.response_phrase,
469        }
470    }
471}
472
473impl<'a> FulfillRequestParams<'a> { pub const METHOD: &'static str = "Fetch.fulfillRequest"; }
474
475impl<'a> crate::CdpCommand<'a> for FulfillRequestParams<'a> {
476    const METHOD: &'static str = "Fetch.fulfillRequest";
477    type Response = crate::EmptyReturns;
478}
479
480/// Continues the request, optionally modifying some of its parameters.
481
482#[derive(Debug, Clone, Serialize, Deserialize, Default)]
483#[serde(rename_all = "camelCase")]
484pub struct ContinueRequestParams<'a> {
485    /// An id the client received in requestPaused event.
486    #[serde(rename = "requestId")]
487    request_id: RequestId<'a>,
488    /// If set, the request url will be modified in a way that's not observable by page.
489    #[serde(skip_serializing_if = "Option::is_none")]
490    url: Option<Cow<'a, str>>,
491    /// If set, the request method is overridden.
492    #[serde(skip_serializing_if = "Option::is_none")]
493    method: Option<Cow<'a, str>>,
494    /// If set, overrides the post data in the request. (Encoded as a base64 string when passed over JSON)
495    #[serde(skip_serializing_if = "Option::is_none", rename = "postData")]
496    post_data: Option<Cow<'a, str>>,
497    /// If set, overrides the request headers. Note that the overrides do not
498    /// extend to subsequent redirect hops, if a redirect happens. Another override
499    /// may be applied to a different request produced by a redirect.
500    #[serde(skip_serializing_if = "Option::is_none")]
501    headers: Option<Vec<HeaderEntry<'a>>>,
502    /// If set, overrides response interception behavior for this request.
503    #[serde(skip_serializing_if = "Option::is_none", rename = "interceptResponse")]
504    intercept_response: Option<bool>,
505}
506
507impl<'a> ContinueRequestParams<'a> {
508    /// Creates a builder for this type with the required parameters:
509    /// * `request_id`: An id the client received in requestPaused event.
510    pub fn builder(request_id: impl Into<RequestId<'a>>) -> ContinueRequestParamsBuilder<'a> {
511        ContinueRequestParamsBuilder {
512            request_id: request_id.into(),
513            url: None,
514            method: None,
515            post_data: None,
516            headers: None,
517            intercept_response: None,
518        }
519    }
520    /// An id the client received in requestPaused event.
521    pub fn request_id(&self) -> &RequestId<'a> { &self.request_id }
522    /// If set, the request url will be modified in a way that's not observable by page.
523    pub fn url(&self) -> Option<&str> { self.url.as_deref() }
524    /// If set, the request method is overridden.
525    pub fn method(&self) -> Option<&str> { self.method.as_deref() }
526    /// If set, overrides the post data in the request. (Encoded as a base64 string when passed over JSON)
527    pub fn post_data(&self) -> Option<&str> { self.post_data.as_deref() }
528    /// If set, overrides the request headers. Note that the overrides do not
529    /// extend to subsequent redirect hops, if a redirect happens. Another override
530    /// may be applied to a different request produced by a redirect.
531    pub fn headers(&self) -> Option<&[HeaderEntry<'a>]> { self.headers.as_deref() }
532    /// If set, overrides response interception behavior for this request.
533    pub fn intercept_response(&self) -> Option<bool> { self.intercept_response }
534}
535
536
537pub struct ContinueRequestParamsBuilder<'a> {
538    request_id: RequestId<'a>,
539    url: Option<Cow<'a, str>>,
540    method: Option<Cow<'a, str>>,
541    post_data: Option<Cow<'a, str>>,
542    headers: Option<Vec<HeaderEntry<'a>>>,
543    intercept_response: Option<bool>,
544}
545
546impl<'a> ContinueRequestParamsBuilder<'a> {
547    /// If set, the request url will be modified in a way that's not observable by page.
548    pub fn url(mut self, url: impl Into<Cow<'a, str>>) -> Self { self.url = Some(url.into()); self }
549    /// If set, the request method is overridden.
550    pub fn method(mut self, method: impl Into<Cow<'a, str>>) -> Self { self.method = Some(method.into()); self }
551    /// If set, overrides the post data in the request. (Encoded as a base64 string when passed over JSON)
552    pub fn post_data(mut self, post_data: impl Into<Cow<'a, str>>) -> Self { self.post_data = Some(post_data.into()); self }
553    /// If set, overrides the request headers. Note that the overrides do not
554    /// extend to subsequent redirect hops, if a redirect happens. Another override
555    /// may be applied to a different request produced by a redirect.
556    pub fn headers(mut self, headers: Vec<HeaderEntry<'a>>) -> Self { self.headers = Some(headers); self }
557    /// If set, overrides response interception behavior for this request.
558    pub fn intercept_response(mut self, intercept_response: bool) -> Self { self.intercept_response = Some(intercept_response); self }
559    pub fn build(self) -> ContinueRequestParams<'a> {
560        ContinueRequestParams {
561            request_id: self.request_id,
562            url: self.url,
563            method: self.method,
564            post_data: self.post_data,
565            headers: self.headers,
566            intercept_response: self.intercept_response,
567        }
568    }
569}
570
571impl<'a> ContinueRequestParams<'a> { pub const METHOD: &'static str = "Fetch.continueRequest"; }
572
573impl<'a> crate::CdpCommand<'a> for ContinueRequestParams<'a> {
574    const METHOD: &'static str = "Fetch.continueRequest";
575    type Response = crate::EmptyReturns;
576}
577
578/// Continues a request supplying authChallengeResponse following authRequired event.
579
580#[derive(Debug, Clone, Serialize, Deserialize, Default)]
581#[serde(rename_all = "camelCase")]
582pub struct ContinueWithAuthParams<'a> {
583    /// An id the client received in authRequired event.
584    #[serde(rename = "requestId")]
585    request_id: RequestId<'a>,
586    /// Response to  with an authChallenge.
587    #[serde(rename = "authChallengeResponse")]
588    auth_challenge_response: AuthChallengeResponse<'a>,
589}
590
591impl<'a> ContinueWithAuthParams<'a> {
592    /// Creates a builder for this type with the required parameters:
593    /// * `request_id`: An id the client received in authRequired event.
594    /// * `auth_challenge_response`: Response to  with an authChallenge.
595    pub fn builder(request_id: impl Into<RequestId<'a>>, auth_challenge_response: AuthChallengeResponse<'a>) -> ContinueWithAuthParamsBuilder<'a> {
596        ContinueWithAuthParamsBuilder {
597            request_id: request_id.into(),
598            auth_challenge_response: auth_challenge_response,
599        }
600    }
601    /// An id the client received in authRequired event.
602    pub fn request_id(&self) -> &RequestId<'a> { &self.request_id }
603    /// Response to  with an authChallenge.
604    pub fn auth_challenge_response(&self) -> &AuthChallengeResponse<'a> { &self.auth_challenge_response }
605}
606
607
608pub struct ContinueWithAuthParamsBuilder<'a> {
609    request_id: RequestId<'a>,
610    auth_challenge_response: AuthChallengeResponse<'a>,
611}
612
613impl<'a> ContinueWithAuthParamsBuilder<'a> {
614    pub fn build(self) -> ContinueWithAuthParams<'a> {
615        ContinueWithAuthParams {
616            request_id: self.request_id,
617            auth_challenge_response: self.auth_challenge_response,
618        }
619    }
620}
621
622impl<'a> ContinueWithAuthParams<'a> { pub const METHOD: &'static str = "Fetch.continueWithAuth"; }
623
624impl<'a> crate::CdpCommand<'a> for ContinueWithAuthParams<'a> {
625    const METHOD: &'static str = "Fetch.continueWithAuth";
626    type Response = crate::EmptyReturns;
627}
628
629/// Continues loading of the paused response, optionally modifying the
630/// response headers. If either responseCode or headers are modified, all of them
631/// must be present.
632
633#[derive(Debug, Clone, Serialize, Deserialize, Default)]
634#[serde(rename_all = "camelCase")]
635pub struct ContinueResponseParams<'a> {
636    /// An id the client received in requestPaused event.
637    #[serde(rename = "requestId")]
638    request_id: RequestId<'a>,
639    /// An HTTP response code. If absent, original response code will be used.
640    #[serde(skip_serializing_if = "Option::is_none", rename = "responseCode")]
641    response_code: Option<i64>,
642    /// A textual representation of responseCode.
643    /// If absent, a standard phrase matching responseCode is used.
644    #[serde(skip_serializing_if = "Option::is_none", rename = "responsePhrase")]
645    response_phrase: Option<Cow<'a, str>>,
646    /// Response headers. If absent, original response headers will be used.
647    #[serde(skip_serializing_if = "Option::is_none", rename = "responseHeaders")]
648    response_headers: Option<Vec<HeaderEntry<'a>>>,
649    /// Alternative way of specifying response headers as a \0-separated
650    /// series of name: value pairs. Prefer the above method unless you
651    /// need to represent some non-UTF8 values that can't be transmitted
652    /// over the protocol as text. (Encoded as a base64 string when passed over JSON)
653    #[serde(skip_serializing_if = "Option::is_none", rename = "binaryResponseHeaders")]
654    binary_response_headers: Option<Cow<'a, str>>,
655}
656
657impl<'a> ContinueResponseParams<'a> {
658    /// Creates a builder for this type with the required parameters:
659    /// * `request_id`: An id the client received in requestPaused event.
660    pub fn builder(request_id: impl Into<RequestId<'a>>) -> ContinueResponseParamsBuilder<'a> {
661        ContinueResponseParamsBuilder {
662            request_id: request_id.into(),
663            response_code: None,
664            response_phrase: None,
665            response_headers: None,
666            binary_response_headers: None,
667        }
668    }
669    /// An id the client received in requestPaused event.
670    pub fn request_id(&self) -> &RequestId<'a> { &self.request_id }
671    /// An HTTP response code. If absent, original response code will be used.
672    pub fn response_code(&self) -> Option<i64> { self.response_code }
673    /// A textual representation of responseCode.
674    /// If absent, a standard phrase matching responseCode is used.
675    pub fn response_phrase(&self) -> Option<&str> { self.response_phrase.as_deref() }
676    /// Response headers. If absent, original response headers will be used.
677    pub fn response_headers(&self) -> Option<&[HeaderEntry<'a>]> { self.response_headers.as_deref() }
678    /// Alternative way of specifying response headers as a \0-separated
679    /// series of name: value pairs. Prefer the above method unless you
680    /// need to represent some non-UTF8 values that can't be transmitted
681    /// over the protocol as text. (Encoded as a base64 string when passed over JSON)
682    pub fn binary_response_headers(&self) -> Option<&str> { self.binary_response_headers.as_deref() }
683}
684
685
686pub struct ContinueResponseParamsBuilder<'a> {
687    request_id: RequestId<'a>,
688    response_code: Option<i64>,
689    response_phrase: Option<Cow<'a, str>>,
690    response_headers: Option<Vec<HeaderEntry<'a>>>,
691    binary_response_headers: Option<Cow<'a, str>>,
692}
693
694impl<'a> ContinueResponseParamsBuilder<'a> {
695    /// An HTTP response code. If absent, original response code will be used.
696    pub fn response_code(mut self, response_code: i64) -> Self { self.response_code = Some(response_code); self }
697    /// A textual representation of responseCode.
698    /// If absent, a standard phrase matching responseCode is used.
699    pub fn response_phrase(mut self, response_phrase: impl Into<Cow<'a, str>>) -> Self { self.response_phrase = Some(response_phrase.into()); self }
700    /// Response headers. If absent, original response headers will be used.
701    pub fn response_headers(mut self, response_headers: Vec<HeaderEntry<'a>>) -> Self { self.response_headers = Some(response_headers); self }
702    /// Alternative way of specifying response headers as a \0-separated
703    /// series of name: value pairs. Prefer the above method unless you
704    /// need to represent some non-UTF8 values that can't be transmitted
705    /// over the protocol as text. (Encoded as a base64 string when passed over JSON)
706    pub fn binary_response_headers(mut self, binary_response_headers: impl Into<Cow<'a, str>>) -> Self { self.binary_response_headers = Some(binary_response_headers.into()); self }
707    pub fn build(self) -> ContinueResponseParams<'a> {
708        ContinueResponseParams {
709            request_id: self.request_id,
710            response_code: self.response_code,
711            response_phrase: self.response_phrase,
712            response_headers: self.response_headers,
713            binary_response_headers: self.binary_response_headers,
714        }
715    }
716}
717
718impl<'a> ContinueResponseParams<'a> { pub const METHOD: &'static str = "Fetch.continueResponse"; }
719
720impl<'a> crate::CdpCommand<'a> for ContinueResponseParams<'a> {
721    const METHOD: &'static str = "Fetch.continueResponse";
722    type Response = crate::EmptyReturns;
723}
724
725/// Causes the body of the response to be received from the server and
726/// returned as a single string. May only be issued for a request that
727/// is paused in the Response stage and is mutually exclusive with
728/// takeResponseBodyForInterceptionAsStream. Calling other methods that
729/// affect the request or disabling fetch domain before body is received
730/// results in an undefined behavior.
731/// Note that the response body is not available for redirects. Requests
732/// paused in the _redirect received_ state may be differentiated by
733/// 'responseCode' and presence of 'location' response header, see
734/// comments to 'requestPaused' for details.
735
736#[derive(Debug, Clone, Serialize, Deserialize, Default)]
737#[serde(rename_all = "camelCase")]
738pub struct GetResponseBodyParams<'a> {
739    /// Identifier for the intercepted request to get body for.
740    #[serde(rename = "requestId")]
741    request_id: RequestId<'a>,
742}
743
744impl<'a> GetResponseBodyParams<'a> {
745    /// Creates a builder for this type with the required parameters:
746    /// * `request_id`: Identifier for the intercepted request to get body for.
747    pub fn builder(request_id: impl Into<RequestId<'a>>) -> GetResponseBodyParamsBuilder<'a> {
748        GetResponseBodyParamsBuilder {
749            request_id: request_id.into(),
750        }
751    }
752    /// Identifier for the intercepted request to get body for.
753    pub fn request_id(&self) -> &RequestId<'a> { &self.request_id }
754}
755
756
757pub struct GetResponseBodyParamsBuilder<'a> {
758    request_id: RequestId<'a>,
759}
760
761impl<'a> GetResponseBodyParamsBuilder<'a> {
762    pub fn build(self) -> GetResponseBodyParams<'a> {
763        GetResponseBodyParams {
764            request_id: self.request_id,
765        }
766    }
767}
768
769/// Causes the body of the response to be received from the server and
770/// returned as a single string. May only be issued for a request that
771/// is paused in the Response stage and is mutually exclusive with
772/// takeResponseBodyForInterceptionAsStream. Calling other methods that
773/// affect the request or disabling fetch domain before body is received
774/// results in an undefined behavior.
775/// Note that the response body is not available for redirects. Requests
776/// paused in the _redirect received_ state may be differentiated by
777/// 'responseCode' and presence of 'location' response header, see
778/// comments to 'requestPaused' for details.
779
780#[derive(Debug, Clone, Serialize, Deserialize, Default)]
781#[serde(rename_all = "camelCase")]
782pub struct GetResponseBodyReturns<'a> {
783    /// Response body.
784    body: Cow<'a, str>,
785    /// True, if content was sent as base64.
786    #[serde(rename = "base64Encoded")]
787    base64_encoded: bool,
788}
789
790impl<'a> GetResponseBodyReturns<'a> {
791    /// Creates a builder for this type with the required parameters:
792    /// * `body`: Response body.
793    /// * `base64_encoded`: True, if content was sent as base64.
794    pub fn builder(body: impl Into<Cow<'a, str>>, base64_encoded: bool) -> GetResponseBodyReturnsBuilder<'a> {
795        GetResponseBodyReturnsBuilder {
796            body: body.into(),
797            base64_encoded: base64_encoded,
798        }
799    }
800    /// Response body.
801    pub fn body(&self) -> &str { self.body.as_ref() }
802    /// True, if content was sent as base64.
803    pub fn base64_encoded(&self) -> bool { self.base64_encoded }
804}
805
806
807pub struct GetResponseBodyReturnsBuilder<'a> {
808    body: Cow<'a, str>,
809    base64_encoded: bool,
810}
811
812impl<'a> GetResponseBodyReturnsBuilder<'a> {
813    pub fn build(self) -> GetResponseBodyReturns<'a> {
814        GetResponseBodyReturns {
815            body: self.body,
816            base64_encoded: self.base64_encoded,
817        }
818    }
819}
820
821impl<'a> GetResponseBodyParams<'a> { pub const METHOD: &'static str = "Fetch.getResponseBody"; }
822
823impl<'a> crate::CdpCommand<'a> for GetResponseBodyParams<'a> {
824    const METHOD: &'static str = "Fetch.getResponseBody";
825    type Response = GetResponseBodyReturns<'a>;
826}
827
828/// Returns a handle to the stream representing the response body.
829/// The request must be paused in the HeadersReceived stage.
830/// Note that after this command the request can't be continued
831/// as is -- client either needs to cancel it or to provide the
832/// response body.
833/// The stream only supports sequential read, IO.read will fail if the position
834/// is specified.
835/// This method is mutually exclusive with getResponseBody.
836/// Calling other methods that affect the request or disabling fetch
837/// domain before body is received results in an undefined behavior.
838
839#[derive(Debug, Clone, Serialize, Deserialize, Default)]
840#[serde(rename_all = "camelCase")]
841pub struct TakeResponseBodyAsStreamParams<'a> {
842    #[serde(rename = "requestId")]
843    request_id: RequestId<'a>,
844}
845
846impl<'a> TakeResponseBodyAsStreamParams<'a> {
847    /// Creates a builder for this type with the required parameters:
848    /// * `request_id`: 
849    pub fn builder(request_id: impl Into<RequestId<'a>>) -> TakeResponseBodyAsStreamParamsBuilder<'a> {
850        TakeResponseBodyAsStreamParamsBuilder {
851            request_id: request_id.into(),
852        }
853    }
854    pub fn request_id(&self) -> &RequestId<'a> { &self.request_id }
855}
856
857
858pub struct TakeResponseBodyAsStreamParamsBuilder<'a> {
859    request_id: RequestId<'a>,
860}
861
862impl<'a> TakeResponseBodyAsStreamParamsBuilder<'a> {
863    pub fn build(self) -> TakeResponseBodyAsStreamParams<'a> {
864        TakeResponseBodyAsStreamParams {
865            request_id: self.request_id,
866        }
867    }
868}
869
870/// Returns a handle to the stream representing the response body.
871/// The request must be paused in the HeadersReceived stage.
872/// Note that after this command the request can't be continued
873/// as is -- client either needs to cancel it or to provide the
874/// response body.
875/// The stream only supports sequential read, IO.read will fail if the position
876/// is specified.
877/// This method is mutually exclusive with getResponseBody.
878/// Calling other methods that affect the request or disabling fetch
879/// domain before body is received results in an undefined behavior.
880
881#[derive(Debug, Clone, Serialize, Deserialize, Default)]
882#[serde(rename_all = "camelCase")]
883pub struct TakeResponseBodyAsStreamReturns<'a> {
884    stream: crate::io::StreamHandle<'a>,
885}
886
887impl<'a> TakeResponseBodyAsStreamReturns<'a> {
888    /// Creates a builder for this type with the required parameters:
889    /// * `stream`: 
890    pub fn builder(stream: crate::io::StreamHandle<'a>) -> TakeResponseBodyAsStreamReturnsBuilder<'a> {
891        TakeResponseBodyAsStreamReturnsBuilder {
892            stream: stream,
893        }
894    }
895    pub fn stream(&self) -> &crate::io::StreamHandle<'a> { &self.stream }
896}
897
898
899pub struct TakeResponseBodyAsStreamReturnsBuilder<'a> {
900    stream: crate::io::StreamHandle<'a>,
901}
902
903impl<'a> TakeResponseBodyAsStreamReturnsBuilder<'a> {
904    pub fn build(self) -> TakeResponseBodyAsStreamReturns<'a> {
905        TakeResponseBodyAsStreamReturns {
906            stream: self.stream,
907        }
908    }
909}
910
911impl<'a> TakeResponseBodyAsStreamParams<'a> { pub const METHOD: &'static str = "Fetch.takeResponseBodyAsStream"; }
912
913impl<'a> crate::CdpCommand<'a> for TakeResponseBodyAsStreamParams<'a> {
914    const METHOD: &'static str = "Fetch.takeResponseBodyAsStream";
915    type Response = TakeResponseBodyAsStreamReturns<'a>;
916}