use crate::{Error, Result};
use std::collections::HashMap;
pub struct ProxyClient {
client: reqwest::Client,
}
impl ProxyClient {
pub fn new() -> Self {
let client = reqwest::Client::new();
Self { client }
}
pub async fn send_request(
&self,
method: reqwest::Method,
url: &str,
headers: &HashMap<String, String>,
body: Option<&[u8]>,
) -> Result<reqwest::Response> {
let mut request = self.client.request(method, url);
for (key, value) in headers {
request = request.header(key, value);
}
if let Some(body_data) = body {
request = request.body(body_data.to_vec());
}
request
.send()
.await
.map_err(|e| Error::internal(format!("Proxy request failed: {}", e)))
}
}
pub struct ProxyResponse {
pub status_code: u16,
pub headers: HashMap<String, String>,
pub body: Option<Vec<u8>>,
}
impl Default for ProxyClient {
fn default() -> Self {
Self::new()
}
}