Skip to main content

http_request/request/proxy/
struct.rs

1use super::*;
2
3/// Proxy configuration for an outgoing HTTP / WebSocket request.
4///
5/// `Proxy` is a value type with no `Arc<RwLock>` wrapping — exactly like
6/// `hyperlane-core`'s plain fields. Construct one with the convenience
7/// constructors below, then pass to `RequestBuilder::proxy(...)` or assign
8/// directly to `RequestConfig::proxy`.
9///
10/// # Examples
11///
12/// ```ignore
13/// use http_request::Proxy;
14///
15/// let p = Proxy::https("proxy.example.com", 7890);
16/// let auth = Proxy::socks5("127.0.0.1", 1080).auth("user", "pass");
17/// ```
18#[derive(Clone, Data, Debug, Eq, PartialEq)]
19pub struct Proxy {
20    /// Proxy protocol family.
21    pub proxy_type: ProxyType,
22    /// Proxy server hostname or IP.
23    pub host: String,
24    /// Proxy server port.
25    pub port: u16,
26    /// Optional username for proxy auth.
27    pub username: Option<String>,
28    /// Optional password for proxy auth.
29    pub password: Option<String>,
30}
31
32/// Async tunnel stream wrapping another async stream, with a buffer of
33/// pre-read bytes that are returned before delegating to the inner stream.
34#[derive(Data)]
35pub struct ProxyTunnelStream {
36    #[get(pub(crate))]
37    #[get_mut(pub(crate))]
38    #[set(pub(crate))]
39    pub(super) inner: BoxAsyncReadWrite,
40    #[get(pub(crate))]
41    #[get_mut(pub(crate))]
42    #[set(pub(crate))]
43    pub(super) pre_read_data: Vec<u8>,
44}
45
46/// Sync tunnel stream wrapping another sync stream, with a buffer of
47/// pre-read bytes that are returned before delegating to the inner stream.
48#[derive(Data)]
49pub struct SyncProxyTunnelStream {
50    #[get(pub(crate))]
51    #[get_mut(pub(crate))]
52    #[set(pub(crate))]
53    pub(super) inner: BoxReadWrite,
54    #[get(pub(crate))]
55    #[get_mut(pub(crate))]
56    #[set(pub(crate))]
57    pub(super) pre_read_data: Vec<u8>,
58}