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/// ```rust
13/// use http_request::{Proxy, ProxyType};
14///
15/// let https = Proxy::https("proxy.example.com", 7890);
16/// assert_eq!(https.get_proxy_type(), &ProxyType::Https);
17/// assert_eq!(https.get_port(), 7890);
18///
19/// let socks = Proxy::socks5("127.0.0.1", 1080).auth("example-user", "example-password");
20/// assert_eq!(socks.get_proxy_type(), &ProxyType::Socks5);
21/// assert_eq!(socks.get_username(), Some("example-user".to_string()));
22/// ```
23#[derive(Clone, Data, Debug, Eq, PartialEq)]
24pub struct Proxy {
25    /// Proxy protocol family.
26    pub(crate) proxy_type: ProxyType,
27    /// Proxy server hostname or IP.
28    pub(crate) host: String,
29    /// Proxy server port.
30    #[get(type(copy))]
31    pub(crate) port: u16,
32    /// Optional username for proxy auth.
33    #[get(type(clone))]
34    pub(crate) username: Option<String>,
35    /// Optional password for proxy auth.
36    #[get(type(clone))]
37    pub(crate) password: Option<String>,
38}
39
40/// Async tunnel stream wrapping another async stream, with a buffer of
41/// pre-read bytes that are returned before delegating to the inner stream.
42#[derive(Data)]
43pub struct ProxyTunnelStream {
44    #[get(pub(super))]
45    #[get_mut(pub(super))]
46    #[set(pub(super))]
47    pub(super) inner: BoxAsyncReadWrite,
48    #[get(pub(super))]
49    #[get_mut(pub(super))]
50    #[set(pub(super))]
51    pub(super) pre_read_data: Vec<u8>,
52}
53
54/// Sync tunnel stream wrapping another sync stream, with a buffer of
55/// pre-read bytes that are returned before delegating to the inner stream.
56#[derive(Data)]
57pub struct SyncProxyTunnelStream {
58    #[get(pub(super))]
59    #[get_mut(pub(super))]
60    #[set(pub(super))]
61    pub(super) inner: BoxReadWrite,
62    #[get(pub(super))]
63    #[get_mut(pub(super))]
64    #[set(pub(super))]
65    pub(super) pre_read_data: Vec<u8>,
66}