Skip to main content

rustenium_cdp_definitions/browser_protocol/fetch/
command_builders.rs

1use super::commands::*;
2#[derive(Debug, Clone, Default)]
3pub struct DisableBuilder;
4impl DisableBuilder {
5    pub fn new() -> Self {
6        Self
7    }
8    pub fn build(self) -> Disable {
9        Disable {
10            method: DisableMethod::Disable,
11            params: DisableParams {},
12        }
13    }
14}
15impl Disable {
16    pub fn builder() -> DisableBuilder {
17        DisableBuilder
18    }
19}
20impl Enable {
21    pub fn builder() -> EnableBuilder {
22        <EnableBuilder as Default>::default()
23    }
24}
25#[derive(Default, Clone)]
26pub struct EnableBuilder {
27    patterns: Option<Vec<super::types::RequestPattern>>,
28    handle_auth_requests: Option<bool>,
29}
30impl EnableBuilder {
31    pub fn pattern(mut self, pattern: impl Into<super::types::RequestPattern>) -> Self {
32        let v = self.patterns.get_or_insert(Vec::new());
33        v.push(pattern.into());
34        self
35    }
36    pub fn patterns<I, S>(mut self, patterns: I) -> Self
37    where
38        I: IntoIterator<Item = S>,
39        S: Into<super::types::RequestPattern>,
40    {
41        let v = self.patterns.get_or_insert(Vec::new());
42        for val in patterns {
43            v.push(val.into());
44        }
45        self
46    }
47    pub fn handle_auth_requests(mut self, handle_auth_requests: impl Into<bool>) -> Self {
48        self.handle_auth_requests = Some(handle_auth_requests.into());
49        self
50    }
51    pub fn build(self) -> Enable {
52        Enable {
53            method: EnableMethod::Enable,
54            params: EnableParams {
55                patterns: self.patterns,
56                handle_auth_requests: self.handle_auth_requests,
57            },
58        }
59    }
60}
61impl FailRequest {
62    pub fn builder() -> FailRequestBuilder {
63        <FailRequestBuilder as Default>::default()
64    }
65}
66#[derive(Default, Clone)]
67pub struct FailRequestBuilder {
68    request_id: Option<super::types::RequestId>,
69    error_reason: Option<crate::browser_protocol::network::types::ErrorReason>,
70}
71impl FailRequestBuilder {
72    pub fn request_id(mut self, request_id: impl Into<super::types::RequestId>) -> Self {
73        self.request_id = Some(request_id.into());
74        self
75    }
76    pub fn error_reason(
77        mut self,
78        error_reason: impl Into<crate::browser_protocol::network::types::ErrorReason>,
79    ) -> Self {
80        self.error_reason = Some(error_reason.into());
81        self
82    }
83    pub fn build(self) -> Result<FailRequest, String> {
84        Ok(FailRequest {
85            method: FailRequestMethod::FailRequest,
86            params: FailRequestParams {
87                request_id: self.request_id.ok_or_else(|| {
88                    format!("Field `{}` is mandatory.", std::stringify!(request_id))
89                })?,
90                error_reason: self.error_reason.ok_or_else(|| {
91                    format!("Field `{}` is mandatory.", std::stringify!(error_reason))
92                })?,
93            },
94        })
95    }
96}
97impl FulfillRequest {
98    pub fn builder() -> FulfillRequestBuilder {
99        <FulfillRequestBuilder as Default>::default()
100    }
101}
102#[derive(Default, Clone)]
103pub struct FulfillRequestBuilder {
104    request_id: Option<super::types::RequestId>,
105    response_code: Option<i64>,
106    response_headers: Option<Vec<super::types::HeaderEntry>>,
107    binary_response_headers: Option<crate::Binary>,
108    body: Option<crate::Binary>,
109    response_phrase: Option<String>,
110}
111impl FulfillRequestBuilder {
112    pub fn request_id(mut self, request_id: impl Into<super::types::RequestId>) -> Self {
113        self.request_id = Some(request_id.into());
114        self
115    }
116    pub fn response_code(mut self, response_code: impl Into<i64>) -> Self {
117        self.response_code = Some(response_code.into());
118        self
119    }
120    pub fn response_header(
121        mut self,
122        response_header: impl Into<super::types::HeaderEntry>,
123    ) -> Self {
124        let v = self.response_headers.get_or_insert(Vec::new());
125        v.push(response_header.into());
126        self
127    }
128    pub fn response_headers<I, S>(mut self, response_headers: I) -> Self
129    where
130        I: IntoIterator<Item = S>,
131        S: Into<super::types::HeaderEntry>,
132    {
133        let v = self.response_headers.get_or_insert(Vec::new());
134        for val in response_headers {
135            v.push(val.into());
136        }
137        self
138    }
139    pub fn binary_response_headers(
140        mut self,
141        binary_response_headers: impl Into<crate::Binary>,
142    ) -> Self {
143        self.binary_response_headers = Some(binary_response_headers.into());
144        self
145    }
146    pub fn body(mut self, body: impl Into<crate::Binary>) -> Self {
147        self.body = Some(body.into());
148        self
149    }
150    pub fn response_phrase(mut self, response_phrase: impl Into<String>) -> Self {
151        self.response_phrase = Some(response_phrase.into());
152        self
153    }
154    pub fn build(self) -> Result<FulfillRequest, String> {
155        Ok(FulfillRequest {
156            method: FulfillRequestMethod::FulfillRequest,
157            params: FulfillRequestParams {
158                request_id: self.request_id.ok_or_else(|| {
159                    format!("Field `{}` is mandatory.", std::stringify!(request_id))
160                })?,
161                response_code: self.response_code.ok_or_else(|| {
162                    format!("Field `{}` is mandatory.", std::stringify!(response_code))
163                })?,
164                response_headers: self.response_headers,
165                binary_response_headers: self.binary_response_headers,
166                body: self.body,
167                response_phrase: self.response_phrase,
168            },
169        })
170    }
171}
172impl ContinueRequest {
173    pub fn builder() -> ContinueRequestBuilder {
174        <ContinueRequestBuilder as Default>::default()
175    }
176}
177#[derive(Default, Clone)]
178pub struct ContinueRequestBuilder {
179    request_id: Option<super::types::RequestId>,
180    url: Option<String>,
181    method: Option<String>,
182    post_data: Option<crate::Binary>,
183    headers: Option<Vec<super::types::HeaderEntry>>,
184    intercept_response: Option<bool>,
185}
186impl ContinueRequestBuilder {
187    pub fn request_id(mut self, request_id: impl Into<super::types::RequestId>) -> Self {
188        self.request_id = Some(request_id.into());
189        self
190    }
191    pub fn url(mut self, url: impl Into<String>) -> Self {
192        self.url = Some(url.into());
193        self
194    }
195    pub fn method(mut self, method: impl Into<String>) -> Self {
196        self.method = Some(method.into());
197        self
198    }
199    pub fn post_data(mut self, post_data: impl Into<crate::Binary>) -> Self {
200        self.post_data = Some(post_data.into());
201        self
202    }
203    pub fn header(mut self, header: impl Into<super::types::HeaderEntry>) -> Self {
204        let v = self.headers.get_or_insert(Vec::new());
205        v.push(header.into());
206        self
207    }
208    pub fn headers<I, S>(mut self, headers: I) -> Self
209    where
210        I: IntoIterator<Item = S>,
211        S: Into<super::types::HeaderEntry>,
212    {
213        let v = self.headers.get_or_insert(Vec::new());
214        for val in headers {
215            v.push(val.into());
216        }
217        self
218    }
219    pub fn intercept_response(mut self, intercept_response: impl Into<bool>) -> Self {
220        self.intercept_response = Some(intercept_response.into());
221        self
222    }
223    pub fn build(self) -> Result<ContinueRequest, String> {
224        Ok(ContinueRequest {
225            method: ContinueRequestMethod::ContinueRequest,
226            params: ContinueRequestParams {
227                request_id: self.request_id.ok_or_else(|| {
228                    format!("Field `{}` is mandatory.", std::stringify!(request_id))
229                })?,
230                url: self.url,
231                method: self.method,
232                post_data: self.post_data,
233                headers: self.headers,
234                intercept_response: self.intercept_response,
235            },
236        })
237    }
238}
239impl ContinueWithAuth {
240    pub fn builder() -> ContinueWithAuthBuilder {
241        <ContinueWithAuthBuilder as Default>::default()
242    }
243}
244#[derive(Default, Clone)]
245pub struct ContinueWithAuthBuilder {
246    request_id: Option<super::types::RequestId>,
247    auth_challenge_response: Option<super::types::AuthChallengeResponse>,
248}
249impl ContinueWithAuthBuilder {
250    pub fn request_id(mut self, request_id: impl Into<super::types::RequestId>) -> Self {
251        self.request_id = Some(request_id.into());
252        self
253    }
254    pub fn auth_challenge_response(
255        mut self,
256        auth_challenge_response: impl Into<super::types::AuthChallengeResponse>,
257    ) -> Self {
258        self.auth_challenge_response = Some(auth_challenge_response.into());
259        self
260    }
261    pub fn build(self) -> Result<ContinueWithAuth, String> {
262        Ok(ContinueWithAuth {
263            method: ContinueWithAuthMethod::ContinueWithAuth,
264            params: ContinueWithAuthParams {
265                request_id: self.request_id.ok_or_else(|| {
266                    format!("Field `{}` is mandatory.", std::stringify!(request_id))
267                })?,
268                auth_challenge_response: self.auth_challenge_response.ok_or_else(|| {
269                    format!(
270                        "Field `{}` is mandatory.",
271                        std::stringify!(auth_challenge_response)
272                    )
273                })?,
274            },
275        })
276    }
277}
278impl ContinueResponse {
279    pub fn builder() -> ContinueResponseBuilder {
280        <ContinueResponseBuilder as Default>::default()
281    }
282}
283#[derive(Default, Clone)]
284pub struct ContinueResponseBuilder {
285    request_id: Option<super::types::RequestId>,
286    response_code: Option<i64>,
287    response_phrase: Option<String>,
288    response_headers: Option<Vec<super::types::HeaderEntry>>,
289    binary_response_headers: Option<crate::Binary>,
290}
291impl ContinueResponseBuilder {
292    pub fn request_id(mut self, request_id: impl Into<super::types::RequestId>) -> Self {
293        self.request_id = Some(request_id.into());
294        self
295    }
296    pub fn response_code(mut self, response_code: impl Into<i64>) -> Self {
297        self.response_code = Some(response_code.into());
298        self
299    }
300    pub fn response_phrase(mut self, response_phrase: impl Into<String>) -> Self {
301        self.response_phrase = Some(response_phrase.into());
302        self
303    }
304    pub fn response_header(
305        mut self,
306        response_header: impl Into<super::types::HeaderEntry>,
307    ) -> Self {
308        let v = self.response_headers.get_or_insert(Vec::new());
309        v.push(response_header.into());
310        self
311    }
312    pub fn response_headers<I, S>(mut self, response_headers: I) -> Self
313    where
314        I: IntoIterator<Item = S>,
315        S: Into<super::types::HeaderEntry>,
316    {
317        let v = self.response_headers.get_or_insert(Vec::new());
318        for val in response_headers {
319            v.push(val.into());
320        }
321        self
322    }
323    pub fn binary_response_headers(
324        mut self,
325        binary_response_headers: impl Into<crate::Binary>,
326    ) -> Self {
327        self.binary_response_headers = Some(binary_response_headers.into());
328        self
329    }
330    pub fn build(self) -> Result<ContinueResponse, String> {
331        Ok(ContinueResponse {
332            method: ContinueResponseMethod::ContinueResponse,
333            params: ContinueResponseParams {
334                request_id: self.request_id.ok_or_else(|| {
335                    format!("Field `{}` is mandatory.", std::stringify!(request_id))
336                })?,
337                response_code: self.response_code,
338                response_phrase: self.response_phrase,
339                response_headers: self.response_headers,
340                binary_response_headers: self.binary_response_headers,
341            },
342        })
343    }
344}
345impl GetResponseBody {
346    pub fn builder() -> GetResponseBodyBuilder {
347        <GetResponseBodyBuilder as Default>::default()
348    }
349}
350#[derive(Default, Clone)]
351pub struct GetResponseBodyBuilder {
352    request_id: Option<super::types::RequestId>,
353}
354impl GetResponseBodyBuilder {
355    pub fn request_id(mut self, request_id: impl Into<super::types::RequestId>) -> Self {
356        self.request_id = Some(request_id.into());
357        self
358    }
359    pub fn build(self) -> Result<GetResponseBody, String> {
360        Ok(GetResponseBody {
361            method: GetResponseBodyMethod::GetResponseBody,
362            params: GetResponseBodyParams {
363                request_id: self.request_id.ok_or_else(|| {
364                    format!("Field `{}` is mandatory.", std::stringify!(request_id))
365                })?,
366            },
367        })
368    }
369}
370impl TakeResponseBodyAsStream {
371    pub fn builder() -> TakeResponseBodyAsStreamBuilder {
372        <TakeResponseBodyAsStreamBuilder as Default>::default()
373    }
374}
375#[derive(Default, Clone)]
376pub struct TakeResponseBodyAsStreamBuilder {
377    request_id: Option<super::types::RequestId>,
378}
379impl TakeResponseBodyAsStreamBuilder {
380    pub fn request_id(mut self, request_id: impl Into<super::types::RequestId>) -> Self {
381        self.request_id = Some(request_id.into());
382        self
383    }
384    pub fn build(self) -> Result<TakeResponseBodyAsStream, String> {
385        Ok(TakeResponseBodyAsStream {
386            method: TakeResponseBodyAsStreamMethod::TakeResponseBodyAsStream,
387            params: TakeResponseBodyAsStreamParams {
388                request_id: self.request_id.ok_or_else(|| {
389                    format!("Field `{}` is mandatory.", std::stringify!(request_id))
390                })?,
391            },
392        })
393    }
394}