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