mockforge_core/proxy/
client.rs

1//! HTTP client for proxy operations
2
3use crate::{Error, Result};
4use std::collections::HashMap;
5
6/// HTTP client for making proxy requests
7pub struct ProxyClient {
8    /// HTTP client instance
9    client: reqwest::Client,
10}
11
12impl ProxyClient {
13    /// Create a new proxy client
14    pub fn new() -> Self {
15        let client = reqwest::Client::new();
16        Self { client }
17    }
18
19    /// Send an HTTP request
20    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        // Add headers
30        for (key, value) in headers {
31            request = request.header(key, value);
32        }
33
34        // Add body if present
35        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
46/// Response from a proxy request
47pub struct ProxyResponse {
48    /// HTTP status code
49    pub status_code: u16,
50    /// Response headers
51    pub headers: std::collections::HashMap<String, String>,
52    /// Response body
53    pub body: Option<Vec<u8>>,
54}
55
56impl Default for ProxyClient {
57    fn default() -> Self {
58        Self::new()
59    }
60}