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    #[get(type(copy))]
26    pub port: u16,
27    /// Optional username for proxy auth.
28    #[get(type(clone))]
29    pub username: Option<String>,
30    /// Optional password for proxy auth.
31    #[get(type(clone))]
32    pub password: Option<String>,
33}
34
35/// Async tunnel stream wrapping another async stream, with a buffer of
36/// pre-read bytes that are returned before delegating to the inner stream.
37#[derive(Data)]
38pub struct ProxyTunnelStream {
39    #[get(pub(super))]
40    #[get_mut(pub(super))]
41    #[set(pub(super))]
42    pub(super) inner: BoxAsyncReadWrite,
43    #[get(pub(super))]
44    #[get_mut(pub(super))]
45    #[set(pub(super))]
46    pub(super) pre_read_data: Vec<u8>,
47}
48
49/// Sync tunnel stream wrapping another sync stream, with a buffer of
50/// pre-read bytes that are returned before delegating to the inner stream.
51#[derive(Data)]
52pub struct SyncProxyTunnelStream {
53    #[get(pub(super))]
54    #[get_mut(pub(super))]
55    #[set(pub(super))]
56    pub(super) inner: BoxReadWrite,
57    #[get(pub(super))]
58    #[get_mut(pub(super))]
59    #[set(pub(super))]
60    pub(super) pre_read_data: Vec<u8>,
61}