1use crate::{
2 clients::{resolve::resolve, SystemHttpClientInterface},
3 url::ValidUrl,
4 Error,
5};
6use std::time::Duration;
7
8#[derive(Debug)]
10pub struct Response {
11 pub body: Vec<u8>,
13}
14
15pub struct RequestBuilder<U: ValidUrl> {
17 url: U,
18 timeout: Option<Duration>,
19}
20impl<U: ValidUrl> RequestBuilder<U> {
21 #[must_use]
23 pub fn new(url: U) -> Self {
24 Self { url, timeout: None }
25 }
26
27 #[must_use]
33 pub fn timeout(mut self, timeout: Option<Duration>) -> Self {
34 self.timeout = match timeout {
35 Some(timeout) if !timeout.is_zero() => Some(timeout),
36 None => None,
37 _ => panic!("Timeout must be non-zero"),
38 };
39 self
40 }
41
42 pub fn send(self) -> Result<Response, Error> {
44 resolve()?.get(self.url.validate()?, self.timeout)
45 }
46}