Skip to main content

cdp_protocol/
fetch.rs

1// Auto-generated from Chrome at version 146.0.7680.165 domain: Fetch
2#![allow(dead_code)]
3use super::io;
4use super::network;
5#[allow(unused_imports)]
6use super::types::*;
7#[allow(unused_imports)]
8use derive_builder::Builder;
9#[allow(unused_imports)]
10use serde::{Deserialize, Serialize};
11#[allow(unused_imports)]
12use serde_json::Value as Json;
13pub type RequestId = String;
14#[allow(deprecated)]
15#[derive(Deserialize, Serialize, Debug, Clone, PartialEq)]
16pub enum RequestStage {
17    #[serde(rename = "Request")]
18    Request,
19    #[serde(rename = "Response")]
20    Response,
21}
22#[allow(deprecated)]
23#[derive(Deserialize, Serialize, Debug, Clone, PartialEq)]
24pub enum AuthChallengeSource {
25    #[serde(rename = "Server")]
26    Server,
27    #[serde(rename = "Proxy")]
28    Proxy,
29}
30#[allow(deprecated)]
31#[derive(Deserialize, Serialize, Debug, Clone, PartialEq)]
32pub enum AuthChallengeResponseResponse {
33    #[serde(rename = "Default")]
34    Default,
35    #[serde(rename = "CancelAuth")]
36    CancelAuth,
37    #[serde(rename = "ProvideCredentials")]
38    ProvideCredentials,
39}
40#[allow(deprecated)]
41#[derive(Deserialize, Serialize, Debug, Clone, PartialEq, Builder)]
42#[builder(setter(into, strip_option))]
43#[serde(rename_all = "camelCase")]
44pub struct RequestPattern {
45    #[builder(default)]
46    #[serde(skip_serializing_if = "Option::is_none")]
47    #[serde(default)]
48    #[doc = "Wildcards (`'*'` -\\> zero or more, `'?'` -\\> exactly one) are allowed. Escape character is\n backslash. Omitting is equivalent to `\"*\"`."]
49    pub url_pattern: Option<String>,
50    #[builder(default)]
51    #[serde(skip_serializing_if = "Option::is_none")]
52    #[doc = "If set, only requests for matching resource types will be intercepted."]
53    pub resource_type: Option<network::ResourceType>,
54    #[builder(default)]
55    #[serde(skip_serializing_if = "Option::is_none")]
56    #[doc = "Stage at which to begin intercepting requests. Default is Request."]
57    pub request_stage: Option<RequestStage>,
58}
59#[allow(deprecated)]
60#[derive(Deserialize, Serialize, Debug, Clone, PartialEq, Builder)]
61#[builder(setter(into, strip_option))]
62#[serde(rename_all = "camelCase")]
63#[doc = "Response HTTP header entry"]
64pub struct HeaderEntry {
65    #[serde(default)]
66    pub name: String,
67    #[serde(default)]
68    pub value: String,
69}
70#[allow(deprecated)]
71#[derive(Deserialize, Serialize, Debug, Clone, PartialEq, Builder)]
72#[builder(setter(into, strip_option))]
73#[serde(rename_all = "camelCase")]
74#[doc = "Authorization challenge for HTTP status code 401 or 407."]
75pub struct AuthChallenge {
76    #[builder(default)]
77    #[serde(skip_serializing_if = "Option::is_none")]
78    #[doc = "Source of the authentication challenge."]
79    pub source: Option<AuthChallengeSource>,
80    #[serde(default)]
81    #[doc = "Origin of the challenger."]
82    pub origin: String,
83    #[serde(default)]
84    #[doc = "The authentication scheme used, such as basic or digest"]
85    pub scheme: String,
86    #[serde(default)]
87    #[doc = "The realm of the challenge. May be empty."]
88    pub realm: String,
89}
90#[allow(deprecated)]
91#[derive(Deserialize, Serialize, Debug, Clone, PartialEq, Builder)]
92#[builder(setter(into, strip_option))]
93#[serde(rename_all = "camelCase")]
94#[doc = "Response to an AuthChallenge."]
95pub struct AuthChallengeResponse {
96    #[doc = "The decision on what to do in response to the authorization challenge.  Default means\n deferring to the default behavior of the net stack, which will likely either the Cancel\n authentication or display a popup dialog box."]
97    pub response: AuthChallengeResponseResponse,
98    #[builder(default)]
99    #[serde(skip_serializing_if = "Option::is_none")]
100    #[serde(default)]
101    #[doc = "The username to provide, possibly empty. Should only be set if response is\n ProvideCredentials."]
102    pub username: Option<String>,
103    #[builder(default)]
104    #[serde(skip_serializing_if = "Option::is_none")]
105    #[serde(default)]
106    #[doc = "The password to provide, possibly empty. Should only be set if response is\n ProvideCredentials."]
107    pub password: Option<String>,
108}
109#[allow(deprecated)]
110#[derive(Deserialize, Serialize, Debug, Clone, PartialEq)]
111pub struct Disable(pub Option<Json>);
112#[allow(deprecated)]
113#[derive(Deserialize, Serialize, Debug, Clone, PartialEq, Builder)]
114#[builder(setter(into, strip_option))]
115#[serde(rename_all = "camelCase")]
116#[doc = "Enables issuing of requestPaused events. A request will be paused until client\n calls one of failRequest, fulfillRequest or continueRequest/continueWithAuth."]
117pub struct Enable {
118    #[builder(default)]
119    #[serde(skip_serializing_if = "Option::is_none")]
120    #[doc = "If specified, only requests matching any of these patterns will produce\n fetchRequested event and will be paused until clients response. If not set,\n all requests will be affected."]
121    pub patterns: Option<Vec<RequestPattern>>,
122    #[builder(default)]
123    #[serde(skip_serializing_if = "Option::is_none")]
124    #[serde(default)]
125    #[doc = "If true, authRequired events will be issued and requests will be paused\n expecting a call to continueWithAuth."]
126    pub handle_auth_requests: Option<bool>,
127}
128#[allow(deprecated)]
129#[derive(Deserialize, Serialize, Debug, Clone, PartialEq, Builder)]
130#[builder(setter(into, strip_option))]
131#[serde(rename_all = "camelCase")]
132#[doc = "Causes the request to fail with specified reason."]
133pub struct FailRequest {
134    #[doc = "An id the client received in requestPaused event."]
135    pub request_id: RequestId,
136    #[doc = "Causes the request to fail with the given reason."]
137    pub error_reason: network::ErrorReason,
138}
139#[allow(deprecated)]
140#[derive(Deserialize, Serialize, Debug, Clone, PartialEq, Builder)]
141#[builder(setter(into, strip_option))]
142#[serde(rename_all = "camelCase")]
143#[doc = "Provides response to the request."]
144pub struct FulfillRequest {
145    #[doc = "An id the client received in requestPaused event."]
146    pub request_id: RequestId,
147    #[serde(default)]
148    #[doc = "An HTTP response code."]
149    pub response_code: JsUInt,
150    #[builder(default)]
151    #[serde(skip_serializing_if = "Option::is_none")]
152    #[doc = "Response headers."]
153    pub response_headers: Option<Vec<HeaderEntry>>,
154    #[builder(default)]
155    #[serde(skip_serializing_if = "Option::is_none")]
156    #[doc = "Alternative way of specifying response headers as a \\0-separated\n series of name: value pairs. Prefer the above method unless you\n need to represent some non-UTF8 values that can't be transmitted\n over the protocol as text."]
157    pub binary_response_headers: Option<Vec<u8>>,
158    #[builder(default)]
159    #[serde(skip_serializing_if = "Option::is_none")]
160    #[doc = "A response body. If absent, original response body will be used if\n the request is intercepted at the response stage and empty body\n will be used if the request is intercepted at the request stage."]
161    pub body: Option<Vec<u8>>,
162    #[builder(default)]
163    #[serde(skip_serializing_if = "Option::is_none")]
164    #[serde(default)]
165    #[doc = "A textual representation of responseCode.\n If absent, a standard phrase matching responseCode is used."]
166    pub response_phrase: Option<String>,
167}
168#[allow(deprecated)]
169#[derive(Deserialize, Serialize, Debug, Clone, PartialEq, Builder)]
170#[builder(setter(into, strip_option))]
171#[serde(rename_all = "camelCase")]
172#[doc = "Continues the request, optionally modifying some of its parameters."]
173pub struct ContinueRequest {
174    #[doc = "An id the client received in requestPaused event."]
175    pub request_id: RequestId,
176    #[builder(default)]
177    #[serde(skip_serializing_if = "Option::is_none")]
178    #[serde(default)]
179    #[doc = "If set, the request url will be modified in a way that's not observable by page."]
180    pub url: Option<String>,
181    #[builder(default)]
182    #[serde(skip_serializing_if = "Option::is_none")]
183    #[serde(default)]
184    #[doc = "If set, the request method is overridden."]
185    pub method: Option<String>,
186    #[builder(default)]
187    #[serde(skip_serializing_if = "Option::is_none")]
188    #[doc = "If set, overrides the post data in the request."]
189    pub post_data: Option<Vec<u8>>,
190    #[builder(default)]
191    #[serde(skip_serializing_if = "Option::is_none")]
192    #[doc = "If set, overrides the request headers. Note that the overrides do not\n extend to subsequent redirect hops, if a redirect happens. Another override\n may be applied to a different request produced by a redirect."]
193    pub headers: Option<Vec<HeaderEntry>>,
194    #[builder(default)]
195    #[serde(skip_serializing_if = "Option::is_none")]
196    #[serde(default)]
197    #[doc = "If set, overrides response interception behavior for this request."]
198    pub intercept_response: Option<bool>,
199}
200#[allow(deprecated)]
201#[derive(Deserialize, Serialize, Debug, Clone, PartialEq, Builder)]
202#[builder(setter(into, strip_option))]
203#[serde(rename_all = "camelCase")]
204#[doc = "Continues a request supplying authChallengeResponse following authRequired event."]
205pub struct ContinueWithAuth {
206    #[doc = "An id the client received in authRequired event."]
207    pub request_id: RequestId,
208    #[doc = "Response to  with an authChallenge."]
209    pub auth_challenge_response: AuthChallengeResponse,
210}
211#[allow(deprecated)]
212#[derive(Deserialize, Serialize, Debug, Clone, PartialEq, Builder)]
213#[builder(setter(into, strip_option))]
214#[serde(rename_all = "camelCase")]
215#[doc = "Continues loading of the paused response, optionally modifying the\n response headers. If either responseCode or headers are modified, all of them\n must be present."]
216pub struct ContinueResponse {
217    #[doc = "An id the client received in requestPaused event."]
218    pub request_id: RequestId,
219    #[builder(default)]
220    #[serde(skip_serializing_if = "Option::is_none")]
221    #[serde(default)]
222    #[doc = "An HTTP response code. If absent, original response code will be used."]
223    pub response_code: Option<JsUInt>,
224    #[builder(default)]
225    #[serde(skip_serializing_if = "Option::is_none")]
226    #[serde(default)]
227    #[doc = "A textual representation of responseCode.\n If absent, a standard phrase matching responseCode is used."]
228    pub response_phrase: Option<String>,
229    #[builder(default)]
230    #[serde(skip_serializing_if = "Option::is_none")]
231    #[doc = "Response headers. If absent, original response headers will be used."]
232    pub response_headers: Option<Vec<HeaderEntry>>,
233    #[builder(default)]
234    #[serde(skip_serializing_if = "Option::is_none")]
235    #[doc = "Alternative way of specifying response headers as a \\0-separated\n series of name: value pairs. Prefer the above method unless you\n need to represent some non-UTF8 values that can't be transmitted\n over the protocol as text."]
236    pub binary_response_headers: Option<Vec<u8>>,
237}
238#[allow(deprecated)]
239#[derive(Deserialize, Serialize, Debug, Clone, PartialEq, Builder)]
240#[builder(setter(into, strip_option))]
241#[serde(rename_all = "camelCase")]
242#[doc = "Causes the body of the response to be received from the server and\n returned as a single string. May only be issued for a request that\n is paused in the Response stage and is mutually exclusive with\n takeResponseBodyForInterceptionAsStream. Calling other methods that\n affect the request or disabling fetch domain before body is received\n results in an undefined behavior.\n Note that the response body is not available for redirects. Requests\n paused in the _redirect received_ state may be differentiated by\n `responseCode` and presence of `location` response header, see\n comments to `requestPaused` for details."]
243pub struct GetResponseBody {
244    #[doc = "Identifier for the intercepted request to get body for."]
245    pub request_id: RequestId,
246}
247#[allow(deprecated)]
248#[derive(Deserialize, Serialize, Debug, Clone, PartialEq, Builder)]
249#[builder(setter(into, strip_option))]
250#[serde(rename_all = "camelCase")]
251#[doc = "Returns a handle to the stream representing the response body.\n The request must be paused in the HeadersReceived stage.\n Note that after this command the request can't be continued\n as is -- client either needs to cancel it or to provide the\n response body.\n The stream only supports sequential read, IO.read will fail if the position\n is specified.\n This method is mutually exclusive with getResponseBody.\n Calling other methods that affect the request or disabling fetch\n domain before body is received results in an undefined behavior."]
252pub struct TakeResponseBodyAsStream {
253    pub request_id: RequestId,
254}
255#[allow(deprecated)]
256#[derive(Deserialize, Serialize, Debug, Clone, PartialEq)]
257#[doc = "Disables the fetch domain."]
258pub struct DisableReturnObject(pub Option<Json>);
259#[allow(deprecated)]
260#[derive(Deserialize, Serialize, Debug, Clone, PartialEq)]
261#[doc = "Enables issuing of requestPaused events. A request will be paused until client\n calls one of failRequest, fulfillRequest or continueRequest/continueWithAuth."]
262pub struct EnableReturnObject(pub Option<Json>);
263#[allow(deprecated)]
264#[derive(Deserialize, Serialize, Debug, Clone, PartialEq)]
265#[doc = "Causes the request to fail with specified reason."]
266pub struct FailRequestReturnObject(pub Option<Json>);
267#[allow(deprecated)]
268#[derive(Deserialize, Serialize, Debug, Clone, PartialEq)]
269#[doc = "Provides response to the request."]
270pub struct FulfillRequestReturnObject(pub Option<Json>);
271#[allow(deprecated)]
272#[derive(Deserialize, Serialize, Debug, Clone, PartialEq)]
273#[doc = "Continues the request, optionally modifying some of its parameters."]
274pub struct ContinueRequestReturnObject(pub Option<Json>);
275#[allow(deprecated)]
276#[derive(Deserialize, Serialize, Debug, Clone, PartialEq)]
277#[doc = "Continues a request supplying authChallengeResponse following authRequired event."]
278pub struct ContinueWithAuthReturnObject(pub Option<Json>);
279#[allow(deprecated)]
280#[derive(Deserialize, Serialize, Debug, Clone, PartialEq)]
281#[doc = "Continues loading of the paused response, optionally modifying the\n response headers. If either responseCode or headers are modified, all of them\n must be present."]
282pub struct ContinueResponseReturnObject(pub Option<Json>);
283#[allow(deprecated)]
284#[derive(Deserialize, Serialize, Debug, Clone, PartialEq, Builder)]
285#[serde(rename_all = "camelCase")]
286#[doc = "Causes the body of the response to be received from the server and\n returned as a single string. May only be issued for a request that\n is paused in the Response stage and is mutually exclusive with\n takeResponseBodyForInterceptionAsStream. Calling other methods that\n affect the request or disabling fetch domain before body is received\n results in an undefined behavior.\n Note that the response body is not available for redirects. Requests\n paused in the _redirect received_ state may be differentiated by\n `responseCode` and presence of `location` response header, see\n comments to `requestPaused` for details."]
287pub struct GetResponseBodyReturnObject {
288    #[serde(default)]
289    #[doc = "Response body."]
290    pub body: String,
291    #[serde(default)]
292    #[doc = "True, if content was sent as base64."]
293    pub base_64_encoded: bool,
294}
295#[allow(deprecated)]
296#[derive(Deserialize, Serialize, Debug, Clone, PartialEq, Builder)]
297#[serde(rename_all = "camelCase")]
298#[doc = "Returns a handle to the stream representing the response body.\n The request must be paused in the HeadersReceived stage.\n Note that after this command the request can't be continued\n as is -- client either needs to cancel it or to provide the\n response body.\n The stream only supports sequential read, IO.read will fail if the position\n is specified.\n This method is mutually exclusive with getResponseBody.\n Calling other methods that affect the request or disabling fetch\n domain before body is received results in an undefined behavior."]
299pub struct TakeResponseBodyAsStreamReturnObject {
300    pub stream: io::StreamHandle,
301}
302#[allow(deprecated)]
303impl Method for Disable {
304    const NAME: &'static str = "Fetch.disable";
305    type ReturnObject = DisableReturnObject;
306}
307#[allow(deprecated)]
308impl Method for Enable {
309    const NAME: &'static str = "Fetch.enable";
310    type ReturnObject = EnableReturnObject;
311}
312#[allow(deprecated)]
313impl Method for FailRequest {
314    const NAME: &'static str = "Fetch.failRequest";
315    type ReturnObject = FailRequestReturnObject;
316}
317#[allow(deprecated)]
318impl Method for FulfillRequest {
319    const NAME: &'static str = "Fetch.fulfillRequest";
320    type ReturnObject = FulfillRequestReturnObject;
321}
322#[allow(deprecated)]
323impl Method for ContinueRequest {
324    const NAME: &'static str = "Fetch.continueRequest";
325    type ReturnObject = ContinueRequestReturnObject;
326}
327#[allow(deprecated)]
328impl Method for ContinueWithAuth {
329    const NAME: &'static str = "Fetch.continueWithAuth";
330    type ReturnObject = ContinueWithAuthReturnObject;
331}
332#[allow(deprecated)]
333impl Method for ContinueResponse {
334    const NAME: &'static str = "Fetch.continueResponse";
335    type ReturnObject = ContinueResponseReturnObject;
336}
337#[allow(deprecated)]
338impl Method for GetResponseBody {
339    const NAME: &'static str = "Fetch.getResponseBody";
340    type ReturnObject = GetResponseBodyReturnObject;
341}
342#[allow(deprecated)]
343impl Method for TakeResponseBodyAsStream {
344    const NAME: &'static str = "Fetch.takeResponseBodyAsStream";
345    type ReturnObject = TakeResponseBodyAsStreamReturnObject;
346}
347#[allow(dead_code)]
348pub mod events {
349    #[allow(unused_imports)]
350    use super::super::types::*;
351    #[allow(unused_imports)]
352    use derive_builder::Builder;
353    #[allow(unused_imports)]
354    use serde::{Deserialize, Serialize};
355    #[allow(unused_imports)]
356    use serde_json::Value as Json;
357    #[allow(deprecated)]
358    #[derive(Deserialize, Serialize, Debug, Clone, PartialEq)]
359    pub struct RequestPausedEvent {
360        pub params: RequestPausedEventParams,
361    }
362    #[allow(deprecated)]
363    #[derive(Deserialize, Serialize, Debug, Clone, PartialEq, Builder)]
364    #[serde(rename_all = "camelCase")]
365    pub struct RequestPausedEventParams {
366        #[doc = "Each request the page makes will have a unique id."]
367        pub request_id: super::RequestId,
368        #[doc = "The details of the request."]
369        pub request: super::super::network::Request,
370        #[doc = "The id of the frame that initiated the request."]
371        pub frame_id: super::super::page::FrameId,
372        #[doc = "How the requested resource will be used."]
373        pub resource_type: super::super::network::ResourceType,
374        #[builder(default)]
375        #[serde(skip_serializing_if = "Option::is_none")]
376        #[doc = "Response error if intercepted at response stage."]
377        pub response_error_reason: Option<super::super::network::ErrorReason>,
378        #[builder(default)]
379        #[serde(skip_serializing_if = "Option::is_none")]
380        #[serde(default)]
381        #[doc = "Response code if intercepted at response stage."]
382        pub response_status_code: Option<JsUInt>,
383        #[builder(default)]
384        #[serde(skip_serializing_if = "Option::is_none")]
385        #[serde(default)]
386        #[doc = "Response status text if intercepted at response stage."]
387        pub response_status_text: Option<String>,
388        #[builder(default)]
389        #[serde(skip_serializing_if = "Option::is_none")]
390        #[doc = "Response headers if intercepted at the response stage."]
391        pub response_headers: Option<Vec<super::HeaderEntry>>,
392        #[builder(default)]
393        #[serde(skip_serializing_if = "Option::is_none")]
394        #[doc = "If the intercepted request had a corresponding Network.requestWillBeSent event fired for it,\n then this networkId will be the same as the requestId present in the requestWillBeSent event."]
395        pub network_id: Option<super::super::network::RequestId>,
396        #[builder(default)]
397        #[serde(skip_serializing_if = "Option::is_none")]
398        #[doc = "If the request is due to a redirect response from the server, the id of the request that\n has caused the redirect."]
399        pub redirected_request_id: Option<super::RequestId>,
400    }
401    #[allow(deprecated)]
402    #[derive(Deserialize, Serialize, Debug, Clone, PartialEq)]
403    pub struct AuthRequiredEvent {
404        pub params: AuthRequiredEventParams,
405    }
406    #[allow(deprecated)]
407    #[derive(Deserialize, Serialize, Debug, Clone, PartialEq, Builder)]
408    #[serde(rename_all = "camelCase")]
409    pub struct AuthRequiredEventParams {
410        #[doc = "Each request the page makes will have a unique id."]
411        pub request_id: super::RequestId,
412        #[doc = "The details of the request."]
413        pub request: super::super::network::Request,
414        #[doc = "The id of the frame that initiated the request."]
415        pub frame_id: super::super::page::FrameId,
416        #[doc = "How the requested resource will be used."]
417        pub resource_type: super::super::network::ResourceType,
418        #[doc = "Details of the Authorization Challenge encountered.\n If this is set, client should respond with continueRequest that\n contains AuthChallengeResponse."]
419        pub auth_challenge: super::AuthChallenge,
420    }
421}