2025-11-25 18:06:12 +00:00
|
|
|
use bytes::Bytes;
|
|
|
|
|
use http::Method;
|
|
|
|
|
use reqwest::header::HeaderMap;
|
|
|
|
|
use serde::Serialize;
|
|
|
|
|
use serde_json::Value;
|
|
|
|
|
use std::time::Duration;
|
|
|
|
|
|
2026-01-07 13:21:40 -08:00
|
|
|
#[derive(Debug, Clone, Copy, Default, PartialEq, Eq)]
|
|
|
|
|
pub enum RequestCompression {
|
|
|
|
|
#[default]
|
|
|
|
|
None,
|
|
|
|
|
Zstd,
|
|
|
|
|
}
|
|
|
|
|
|
2025-11-25 18:06:12 +00:00
|
|
|
#[derive(Debug, Clone)]
|
|
|
|
|
pub struct Request {
|
|
|
|
|
pub method: Method,
|
|
|
|
|
pub url: String,
|
|
|
|
|
pub headers: HeaderMap,
|
|
|
|
|
pub body: Option<Value>,
|
2026-01-07 13:21:40 -08:00
|
|
|
pub compression: RequestCompression,
|
2025-11-25 18:06:12 +00:00
|
|
|
pub timeout: Option<Duration>,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl Request {
|
|
|
|
|
pub fn new(method: Method, url: String) -> Self {
|
|
|
|
|
Self {
|
|
|
|
|
method,
|
|
|
|
|
url,
|
|
|
|
|
headers: HeaderMap::new(),
|
|
|
|
|
body: None,
|
2026-01-07 13:21:40 -08:00
|
|
|
compression: RequestCompression::None,
|
2025-11-25 18:06:12 +00:00
|
|
|
timeout: None,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn with_json<T: Serialize>(mut self, body: &T) -> Self {
|
|
|
|
|
self.body = serde_json::to_value(body).ok();
|
|
|
|
|
self
|
|
|
|
|
}
|
2026-01-07 13:21:40 -08:00
|
|
|
|
|
|
|
|
pub fn with_compression(mut self, compression: RequestCompression) -> Self {
|
|
|
|
|
self.compression = compression;
|
|
|
|
|
self
|
|
|
|
|
}
|
2025-11-25 18:06:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[derive(Debug, Clone)]
|
|
|
|
|
pub struct Response {
|
|
|
|
|
pub status: http::StatusCode,
|
|
|
|
|
pub headers: HeaderMap,
|
|
|
|
|
pub body: Bytes,
|
|
|
|
|
}
|