Skip to main content

leyline/core/request/
context.rs

1use super::RequestBuilder;
2use crate::cookie::Jar;
3use crate::core::Result;
4use crate::core::into_url::IntoUrl;
5
6impl RequestBuilder {
7    pub fn cookie_jar(mut self, jar: Jar) -> Self {
8        self.session = self.session.with_cookie_jar(jar);
9        self
10    }
11
12    pub fn initiator(mut self, page: impl IntoUrl) -> Self {
13        match page.into_url_with_base(self.session.base_url()) {
14            Ok(page) => self.initiator = Some(page),
15            Err(err) => self.fail(err),
16        }
17        self
18    }
19
20    pub fn tag(mut self, tag: impl Into<String>) -> Self {
21        self.tag = Some(tag.into());
22        self
23    }
24
25    pub fn error_for_status(mut self) -> Self {
26        self.status_errors = true;
27        self
28    }
29
30    pub async fn download(
31        self,
32        path: impl AsRef<std::path::Path>,
33        limit: Option<u64>,
34    ) -> Result<u64> {
35        let deadline = self.session.deadline(self.timeouts.as_ref());
36        self.stream()
37            .send()
38            .await?
39            .error_for_status_with_body(&deadline)
40            .await?
41            .download_to(path, limit)
42            .await
43    }
44}