use crate::{
clients::{resolve::resolve, SystemHttpClientInterface},
url::ValidUrl,
Error,
};
use std::time::Duration;
#[derive(Debug)]
pub struct Response {
pub body: Vec<u8>,
}
pub struct RequestBuilder<U: ValidUrl> {
url: U,
timeout: Option<Duration>,
}
impl<U: ValidUrl> RequestBuilder<U> {
#[must_use]
pub fn new(url: U) -> Self {
Self { url, timeout: None }
}
#[must_use]
pub fn timeout(mut self, timeout: Option<Duration>) -> Self {
self.timeout = match timeout {
Some(timeout) if !timeout.is_zero() => Some(timeout),
None => None,
_ => panic!("Timeout must be non-zero"),
};
self
}
pub fn send(self) -> Result<Response, Error> {
resolve()?.get(self.url.validate()?, self.timeout)
}
}