mockforge_core/proxy/
client.rs1use crate::{Error, Result};
4use std::collections::HashMap;
5
6pub struct ProxyClient {
8 client: reqwest::Client,
10}
11
12impl ProxyClient {
13 pub fn new() -> Self {
15 let client = reqwest::Client::new();
16 Self { client }
17 }
18
19 pub async fn send_request(
21 &self,
22 method: reqwest::Method,
23 url: &str,
24 headers: &HashMap<String, String>,
25 body: Option<&[u8]>,
26 ) -> Result<reqwest::Response> {
27 let mut request = self.client.request(method, url);
28
29 for (key, value) in headers {
31 request = request.header(key, value);
32 }
33
34 if let Some(body_data) = body {
36 request = request.body(body_data.to_vec());
37 }
38
39 request
40 .send()
41 .await
42 .map_err(|e| Error::generic(format!("Proxy request failed: {}", e)))
43 }
44}
45
46pub struct ProxyResponse {
48 pub status_code: u16,
50 pub headers: std::collections::HashMap<String, String>,
52 pub body: Option<Vec<u8>>,
54}
55
56impl Default for ProxyClient {
57 fn default() -> Self {
58 Self::new()
59 }
60}