Skip to main content

cdp_driver/protocol/
fetch.rs

1// @generated by `just generate-methods` from protocol/*.json.
2// Do not edit by hand; edit xtask/ and regenerate.
3
4//! A domain for letting clients substitute browser's network layer with
5//! client code.
6//!
7//! Types, command parameters and event payloads for the `Fetch`
8//! domain. The method-name constants for the same domain are in
9//! [`crate::methods`].
10
11use serde::{Deserialize, Serialize};
12
13/// Unique request identifier. Note that this does not identify individual
14/// HTTP requests that are part of a network request.
15pub type RequestId = String;
16
17/// Stages of the request to handle. Request will intercept before the request
18/// is sent. Response will intercept after the response is received (but
19/// before response body is received).
20#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
21pub enum RequestStage {
22    /// `Request`
23    Request,
24    /// `Response`
25    Response,
26    /// A value this vendored schema does not list. Chrome adds values ahead of
27    /// the published protocol, so an unrecognised one is kept as it arrived
28    /// rather than failing the payload it came in.
29    #[serde(untagged)]
30    Unrecognized(String),
31}
32
33#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
34pub struct RequestPattern {
35    /// Wildcards (`'*'` -\> zero or more, `'?'` -\> exactly one) are allowed.
36    /// Escape character is backslash. Omitting is equivalent to `"*"`.
37    #[serde(
38        rename = "urlPattern",
39        default,
40        skip_serializing_if = "Option::is_none"
41    )]
42    pub url_pattern: Option<String>,
43    /// If set, only requests for matching resource types will be intercepted.
44    #[serde(
45        rename = "resourceType",
46        default,
47        skip_serializing_if = "Option::is_none"
48    )]
49    pub resource_type: Option<crate::protocol::network::ResourceType>,
50    /// Stage at which to begin intercepting requests. Default is Request.
51    #[serde(
52        rename = "requestStage",
53        default,
54        skip_serializing_if = "Option::is_none"
55    )]
56    pub request_stage: Option<RequestStage>,
57}
58
59/// Response HTTP header entry
60#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
61pub struct HeaderEntry {
62    pub name: String,
63    pub value: String,
64}
65
66/// Authorization challenge for HTTP status code 401 or 407.
67#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
68pub struct AuthChallenge {
69    /// Source of the authentication challenge.
70    #[serde(default, skip_serializing_if = "Option::is_none")]
71    pub source: Option<AuthChallengeSource>,
72    /// Origin of the challenger.
73    pub origin: String,
74    /// The authentication scheme used, such as basic or digest
75    pub scheme: String,
76    /// The realm of the challenge. May be empty.
77    pub realm: String,
78}
79
80/// The values `source` accepts on `AuthChallenge`.
81#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
82pub enum AuthChallengeSource {
83    /// `Server`
84    Server,
85    /// `Proxy`
86    Proxy,
87    /// A value this vendored schema does not list. Chrome adds values ahead of
88    /// the published protocol, so an unrecognised one is kept as it arrived
89    /// rather than failing the payload it came in.
90    #[serde(untagged)]
91    Unrecognized(String),
92}
93
94/// Response to an AuthChallenge.
95#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
96pub struct AuthChallengeResponse {
97    /// The decision on what to do in response to the authorization challenge.
98    /// Default means deferring to the default behavior of the net stack, which
99    /// will likely either the Cancel authentication or display a popup dialog
100    /// box.
101    pub response: AuthChallengeResponseResponse,
102    /// The username to provide, possibly empty. Should only be set if response is
103    /// ProvideCredentials.
104    #[serde(default, skip_serializing_if = "Option::is_none")]
105    pub username: Option<String>,
106    /// The password to provide, possibly empty. Should only be set if response is
107    /// ProvideCredentials.
108    #[serde(default, skip_serializing_if = "Option::is_none")]
109    pub password: Option<String>,
110}
111
112/// The values `response` accepts on `AuthChallengeResponse`.
113#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
114pub enum AuthChallengeResponseResponse {
115    /// `Default`
116    Default,
117    /// `CancelAuth`
118    CancelAuth,
119    /// `ProvideCredentials`
120    ProvideCredentials,
121    /// A value this vendored schema does not list. Chrome adds values ahead of
122    /// the published protocol, so an unrecognised one is kept as it arrived
123    /// rather than failing the payload it came in.
124    #[serde(untagged)]
125    Unrecognized(String),
126}
127
128/// Disables the fetch domain.
129///
130/// Parameters of `Fetch.disable`.
131#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
132pub struct DisableParams {}
133
134impl crate::typed::Command for DisableParams {
135    const METHOD: &'static str = "Fetch.disable";
136    type Returns = crate::typed::NoReturns;
137}
138
139/// Enables issuing of requestPaused events. A request will be paused until
140/// client calls one of failRequest, fulfillRequest or
141/// continueRequest/continueWithAuth.
142///
143/// Parameters of `Fetch.enable`.
144#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
145pub struct EnableParams {
146    /// If specified, only requests matching any of these patterns will produce
147    /// fetchRequested event and will be paused until clients response. If not
148    /// set, all requests will be affected.
149    #[serde(default, skip_serializing_if = "Option::is_none")]
150    pub patterns: Option<Vec<RequestPattern>>,
151    /// If true, authRequired events will be issued and requests will be paused
152    /// expecting a call to continueWithAuth.
153    #[serde(
154        rename = "handleAuthRequests",
155        default,
156        skip_serializing_if = "Option::is_none"
157    )]
158    pub handle_auth_requests: Option<bool>,
159}
160
161impl crate::typed::Command for EnableParams {
162    const METHOD: &'static str = "Fetch.enable";
163    type Returns = crate::typed::NoReturns;
164}
165
166/// Causes the request to fail with specified reason.
167///
168/// Parameters of `Fetch.failRequest`.
169#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
170pub struct FailRequestParams {
171    /// An id the client received in requestPaused event.
172    #[serde(rename = "requestId")]
173    pub request_id: RequestId,
174    /// Causes the request to fail with the given reason.
175    #[serde(rename = "errorReason")]
176    pub error_reason: crate::protocol::network::ErrorReason,
177}
178
179impl crate::typed::Command for FailRequestParams {
180    const METHOD: &'static str = "Fetch.failRequest";
181    type Returns = crate::typed::NoReturns;
182}
183
184/// Provides response to the request.
185///
186/// Parameters of `Fetch.fulfillRequest`.
187#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
188pub struct FulfillRequestParams {
189    /// An id the client received in requestPaused event.
190    #[serde(rename = "requestId")]
191    pub request_id: RequestId,
192    /// An HTTP response code.
193    #[serde(rename = "responseCode")]
194    pub response_code: i64,
195    /// Response headers.
196    #[serde(
197        rename = "responseHeaders",
198        default,
199        skip_serializing_if = "Option::is_none"
200    )]
201    pub response_headers: Option<Vec<HeaderEntry>>,
202    /// Alternative way of specifying response headers as a \0-separated series of
203    /// name: value pairs. Prefer the above method unless you need to represent
204    /// some non-UTF8 values that can't be transmitted over the protocol as text.
205    /// (Encoded as a base64 string when passed over JSON)
206    #[serde(
207        rename = "binaryResponseHeaders",
208        default,
209        skip_serializing_if = "Option::is_none"
210    )]
211    pub binary_response_headers: Option<String>,
212    /// A response body. If absent, original response body will be used if the
213    /// request is intercepted at the response stage and empty body will be used
214    /// if the request is intercepted at the request stage. (Encoded as a base64
215    /// string when passed over JSON)
216    #[serde(default, skip_serializing_if = "Option::is_none")]
217    pub body: Option<String>,
218    /// A textual representation of responseCode. If absent, a standard phrase
219    /// matching responseCode is used.
220    #[serde(
221        rename = "responsePhrase",
222        default,
223        skip_serializing_if = "Option::is_none"
224    )]
225    pub response_phrase: Option<String>,
226}
227
228impl crate::typed::Command for FulfillRequestParams {
229    const METHOD: &'static str = "Fetch.fulfillRequest";
230    type Returns = crate::typed::NoReturns;
231}
232
233/// Continues the request, optionally modifying some of its parameters.
234///
235/// Parameters of `Fetch.continueRequest`.
236#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
237pub struct ContinueRequestParams {
238    /// An id the client received in requestPaused event.
239    #[serde(rename = "requestId")]
240    pub request_id: RequestId,
241    /// If set, the request url will be modified in a way that's not observable by
242    /// page.
243    #[serde(default, skip_serializing_if = "Option::is_none")]
244    pub url: Option<String>,
245    /// If set, the request method is overridden.
246    #[serde(default, skip_serializing_if = "Option::is_none")]
247    pub method: Option<String>,
248    /// If set, overrides the post data in the request. (Encoded as a base64
249    /// string when passed over JSON)
250    #[serde(rename = "postData", default, skip_serializing_if = "Option::is_none")]
251    pub post_data: Option<String>,
252    /// If set, overrides the request headers. Note that the overrides do not
253    /// extend to subsequent redirect hops, if a redirect happens. Another
254    /// override may be applied to a different request produced by a redirect.
255    #[serde(default, skip_serializing_if = "Option::is_none")]
256    pub headers: Option<Vec<HeaderEntry>>,
257    /// If set, overrides response interception behavior for this request.
258    ///
259    /// Experimental: may change without notice.
260    #[serde(
261        rename = "interceptResponse",
262        default,
263        skip_serializing_if = "Option::is_none"
264    )]
265    pub intercept_response: Option<bool>,
266}
267
268impl crate::typed::Command for ContinueRequestParams {
269    const METHOD: &'static str = "Fetch.continueRequest";
270    type Returns = crate::typed::NoReturns;
271}
272
273/// Continues a request supplying authChallengeResponse following authRequired
274/// event.
275///
276/// Parameters of `Fetch.continueWithAuth`.
277#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
278pub struct ContinueWithAuthParams {
279    /// An id the client received in authRequired event.
280    #[serde(rename = "requestId")]
281    pub request_id: RequestId,
282    /// Response to with an authChallenge.
283    #[serde(rename = "authChallengeResponse")]
284    pub auth_challenge_response: AuthChallengeResponse,
285}
286
287impl crate::typed::Command for ContinueWithAuthParams {
288    const METHOD: &'static str = "Fetch.continueWithAuth";
289    type Returns = crate::typed::NoReturns;
290}
291
292/// Continues loading of the paused response, optionally modifying the
293/// response headers. If either responseCode or headers are modified, all of
294/// them must be present.
295///
296/// Experimental: may change without notice.
297///
298/// Parameters of `Fetch.continueResponse`.
299#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
300pub struct ContinueResponseParams {
301    /// An id the client received in requestPaused event.
302    #[serde(rename = "requestId")]
303    pub request_id: RequestId,
304    /// An HTTP response code. If absent, original response code will be used.
305    #[serde(
306        rename = "responseCode",
307        default,
308        skip_serializing_if = "Option::is_none"
309    )]
310    pub response_code: Option<i64>,
311    /// A textual representation of responseCode. If absent, a standard phrase
312    /// matching responseCode is used.
313    #[serde(
314        rename = "responsePhrase",
315        default,
316        skip_serializing_if = "Option::is_none"
317    )]
318    pub response_phrase: Option<String>,
319    /// Response headers. If absent, original response headers will be used.
320    #[serde(
321        rename = "responseHeaders",
322        default,
323        skip_serializing_if = "Option::is_none"
324    )]
325    pub response_headers: Option<Vec<HeaderEntry>>,
326    /// Alternative way of specifying response headers as a \0-separated series of
327    /// name: value pairs. Prefer the above method unless you need to represent
328    /// some non-UTF8 values that can't be transmitted over the protocol as text.
329    /// (Encoded as a base64 string when passed over JSON)
330    #[serde(
331        rename = "binaryResponseHeaders",
332        default,
333        skip_serializing_if = "Option::is_none"
334    )]
335    pub binary_response_headers: Option<String>,
336}
337
338impl crate::typed::Command for ContinueResponseParams {
339    const METHOD: &'static str = "Fetch.continueResponse";
340    type Returns = crate::typed::NoReturns;
341}
342
343/// Causes the body of the response to be received from the server and
344/// returned as a single string. May only be issued for a request that is
345/// paused in the Response stage and is mutually exclusive with
346/// takeResponseBodyForInterceptionAsStream. Calling other methods that affect
347/// the request or disabling fetch domain before body is received results in
348/// an undefined behavior. Note that the response body is not available for
349/// redirects. Requests paused in the _redirect received_ state may be
350/// differentiated by `responseCode` and presence of `location` response
351/// header, see comments to `requestPaused` for details.
352///
353/// Parameters of `Fetch.getResponseBody`.
354#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
355pub struct GetResponseBodyParams {
356    /// Identifier for the intercepted request to get body for.
357    #[serde(rename = "requestId")]
358    pub request_id: RequestId,
359}
360
361/// What `Fetch.getResponseBody` answers with.
362#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
363pub struct GetResponseBodyReturns {
364    /// Response body.
365    pub body: String,
366    /// True, if content was sent as base64.
367    #[serde(rename = "base64Encoded")]
368    pub base64_encoded: bool,
369}
370
371impl crate::typed::Command for GetResponseBodyParams {
372    const METHOD: &'static str = "Fetch.getResponseBody";
373    type Returns = GetResponseBodyReturns;
374}
375
376/// Returns a handle to the stream representing the response body. The request
377/// must be paused in the HeadersReceived stage. Note that after this command
378/// the request can't be continued as is -- client either needs to cancel it
379/// or to provide the response body. The stream only supports sequential read,
380/// IO.read will fail if the position is specified. This method is mutually
381/// exclusive with getResponseBody. Calling other methods that affect the
382/// request or disabling fetch domain before body is received results in an
383/// undefined behavior.
384///
385/// Parameters of `Fetch.takeResponseBodyAsStream`.
386#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
387pub struct TakeResponseBodyAsStreamParams {
388    #[serde(rename = "requestId")]
389    pub request_id: RequestId,
390}
391
392/// What `Fetch.takeResponseBodyAsStream` answers with.
393#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
394pub struct TakeResponseBodyAsStreamReturns {
395    pub stream: crate::protocol::io::StreamHandle,
396}
397
398impl crate::typed::Command for TakeResponseBodyAsStreamParams {
399    const METHOD: &'static str = "Fetch.takeResponseBodyAsStream";
400    type Returns = TakeResponseBodyAsStreamReturns;
401}
402
403/// Issued when the domain is enabled and the request URL matches the
404/// specified filter. The request is paused until the client responds with one
405/// of continueRequest, failRequest or fulfillRequest. The stage of the
406/// request can be determined by presence of responseErrorReason and
407/// responseStatusCode -- the request is at the response stage if either of
408/// these fields is present and in the request stage otherwise. Redirect
409/// responses and subsequent requests are reported similarly to regular
410/// responses and requests. Redirect responses may be distinguished by the
411/// value of `responseStatusCode` (which is one of 301, 302, 303, 307, 308)
412/// along with presence of the `location` header. Requests resulting from a
413/// redirect will have `redirectedRequestId` field set.
414///
415/// Payload of the `Fetch.requestPaused` event.
416#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
417pub struct RequestPausedEvent {
418    /// Each request the page makes will have a unique id.
419    #[serde(rename = "requestId")]
420    pub request_id: RequestId,
421    /// The details of the request.
422    pub request: crate::protocol::network::Request,
423    /// The id of the frame that initiated the request.
424    #[serde(rename = "frameId")]
425    pub frame_id: crate::protocol::page::FrameId,
426    /// How the requested resource will be used.
427    #[serde(rename = "resourceType")]
428    pub resource_type: crate::protocol::network::ResourceType,
429    /// Response error if intercepted at response stage.
430    #[serde(
431        rename = "responseErrorReason",
432        default,
433        skip_serializing_if = "Option::is_none"
434    )]
435    pub response_error_reason: Option<crate::protocol::network::ErrorReason>,
436    /// Response code if intercepted at response stage.
437    #[serde(
438        rename = "responseStatusCode",
439        default,
440        skip_serializing_if = "Option::is_none"
441    )]
442    pub response_status_code: Option<i64>,
443    /// Response status text if intercepted at response stage.
444    #[serde(
445        rename = "responseStatusText",
446        default,
447        skip_serializing_if = "Option::is_none"
448    )]
449    pub response_status_text: Option<String>,
450    /// Response headers if intercepted at the response stage.
451    #[serde(
452        rename = "responseHeaders",
453        default,
454        skip_serializing_if = "Option::is_none"
455    )]
456    pub response_headers: Option<Vec<HeaderEntry>>,
457    /// If the intercepted request had a corresponding Network.requestWillBeSent
458    /// event fired for it, then this networkId will be the same as the requestId
459    /// present in the requestWillBeSent event.
460    #[serde(rename = "networkId", default, skip_serializing_if = "Option::is_none")]
461    pub network_id: Option<crate::protocol::network::RequestId>,
462    /// If the request is due to a redirect response from the server, the id of
463    /// the request that has caused the redirect.
464    ///
465    /// Experimental: may change without notice.
466    #[serde(
467        rename = "redirectedRequestId",
468        default,
469        skip_serializing_if = "Option::is_none"
470    )]
471    pub redirected_request_id: Option<RequestId>,
472}
473
474impl crate::typed::Event for RequestPausedEvent {
475    const METHOD: &'static str = "Fetch.requestPaused";
476}
477
478/// Issued when the domain is enabled with handleAuthRequests set to true. The
479/// request is paused until client responds with continueWithAuth.
480///
481/// Payload of the `Fetch.authRequired` event.
482#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
483pub struct AuthRequiredEvent {
484    /// Each request the page makes will have a unique id.
485    #[serde(rename = "requestId")]
486    pub request_id: RequestId,
487    /// The details of the request.
488    pub request: crate::protocol::network::Request,
489    /// The id of the frame that initiated the request.
490    #[serde(rename = "frameId")]
491    pub frame_id: crate::protocol::page::FrameId,
492    /// How the requested resource will be used.
493    #[serde(rename = "resourceType")]
494    pub resource_type: crate::protocol::network::ResourceType,
495    /// Details of the Authorization Challenge encountered. If this is set, client
496    /// should respond with continueRequest that contains AuthChallengeResponse.
497    #[serde(rename = "authChallenge")]
498    pub auth_challenge: AuthChallenge,
499}
500
501impl crate::typed::Event for AuthRequiredEvent {
502    const METHOD: &'static str = "Fetch.authRequired";
503}