1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
//! HTTP proxy tunneling module
//!
//! Implements HTTP-over-HTTP-proxy connections, supporting both CONNECT
//! tunneling (for HTTPS/FTP) and forward proxy mode (absolute URI for
//! plain HTTP). Collapses the C++ command chain:
//!
//! - `AbstractProxyRequestCommand` (sends proxy request)
//! - `AbstractProxyResponseCommand` (validates proxy response, non-200 = error)
//! - `HttpProxyRequestCommand` (builds CONNECT or forward request)
//! - `HttpProxyResponseCommand` (reads response, proceeds to next command)
//!
//! into a single async function using Rust's async/await model.
//!
//! # Proxy Modes
//!
//! - **Tunnel**: `CONNECT host:port HTTP/1.1` — transparent TCP tunnel
//! for HTTPS and FTP-over-proxy connections.
//! - **Forward**: Absolute-URI forwarding — `GET http://target/path HTTP/1.1`
//! for plain HTTP through a proxy.
use Duration;
use TcpStream;
use crateResult;
use HttpProxyTunnel;
// ---------------------------------------------------------------------------
// HttpProxyType
// ---------------------------------------------------------------------------
/// The type of proxy connection that was established.
// ---------------------------------------------------------------------------
// HttpProxyTunnelConfig
// ---------------------------------------------------------------------------
/// Configuration for establishing an HTTP proxy tunnel or forward connection.
// ---------------------------------------------------------------------------
// HttpProxyTunnelResult
// ---------------------------------------------------------------------------
/// Result of successfully establishing a proxy connection.
// ---------------------------------------------------------------------------
// Top-level entry point
// ---------------------------------------------------------------------------
/// Establish an HTTP proxy connection (tunnel or forward).
///
/// This is the primary entry point, equivalent to the C++ command chain:
/// `AbstractProxyRequestCommand` + `AbstractProxyResponseCommand` +
/// `HttpProxyRequestCommand` + `HttpProxyResponseCommand`.
///
/// - For tunnel mode, sends `CONNECT host:port HTTP/1.1` and validates the
/// proxy response. On success the `TcpStream` is a transparent tunnel.
/// - For forward mode, connects to the proxy and returns the `TcpStream`
/// for the caller to send the absolute-URI request through.
/// - Handles 407 Proxy Authentication Required with Basic/Digest retry.
///
/// # Errors
///
/// - `RecoverableError::Timeout` on connection or read timeout
/// - `RecoverableError::TemporaryNetworkFailure` on proxy rejection,
/// authentication failure, or I/O errors
pub async