You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+1Lines changed: 1 addition & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -18,6 +18,7 @@ It's a fundation layer for building your own proxy-based tools.
18
18
-**Certificate generation**: Dynamically generate and sign certificates for intercepted HTTPS traffic
19
19
-**Request/Response interception**: Modify, log, or block HTTP(S) traffic in real-time
20
20
-**Lightweight**: Pure Python implementation with only cryptography as a direct external dependency
21
+
-**Optional implementation of forward proxy**: The implementation to forward HTTP request can be replace in order to use different HTTP client implementation
This guide covers advanced usage of asyncio-https-proxy using the lower-level `HTTPSProxyHandler` for complete control over request handling and forwarding logic.
4
+
5
+
## When to Use HTTPSProxyHandler
6
+
7
+
Use the base `HTTPSProxyHandler` when you need:
8
+
9
+
-**Complete control** over request forwarding logic
For most use cases, [HTTPSForwardProxyHandler](reference/https_forward_proxy_handler.md) with automatic forwarding is recommended. See the [Getting Started](getting-started.md) guide.
14
+
15
+
## HTTPSProxyHandler Overview
16
+
17
+
The `HTTPSProxyHandler` is the base class that provides:
18
+
19
+
- Request parsing and lifecycle hooks
20
+
- Response writing utilities
21
+
- Request body reading capabilities
22
+
-**No automatic forwarding** - you implement all logic yourself
23
+
24
+
## Basic HTTPSProxyHandler Example
25
+
26
+
Here's a complete example using `HTTPSProxyHandler` with httpx for request forwarding:
27
+
28
+
```python title="base_usage.py"
29
+
--8<--"examples/base_usage.py"
30
+
```
31
+
32
+
33
+
## Handler Lifecycle Methods
34
+
35
+
The `HTTPSProxyHandler` provides these lifecycle hooks:
36
+
37
+
### `on_client_connected()`
38
+
Called when a client connects and sends a request. This is where you implement your main request handling logic.
39
+
40
+
### `on_request_received()`
41
+
Called after the request is fully parsed. Use for logging or request inspection.
42
+
43
+
### Helper Methods
44
+
45
+
-`self.read_request_body()` - Async generator for request body chunks
46
+
-`self.write_response(data)` - Write response data to client
47
+
-`self.flush_response()` - Flush response data to client
48
+
49
+
## Error Handling Best Practices
50
+
51
+
```python
52
+
asyncdefon_client_connected(self):
53
+
try:
54
+
awaitself._handle_request()
55
+
except httpx.ConnectTimeout:
56
+
awaitself._send_error(504, "Gateway Timeout")
57
+
except httpx.ConnectError:
58
+
awaitself._send_error(502, "Bad Gateway")
59
+
exceptExceptionas e:
60
+
print(f"Unexpected error: {e}")
61
+
awaitself._send_error(500, "Internal Server Error")
@@ -12,7 +12,7 @@ asyncio-https-proxy is an embeddable, asyncio-based HTTPS forward proxy server t
12
12
: The proxy can intercept HTTPS traffic by acting as a man-in-the-middle. It generates certificates on-the-fly using its own Certificate Authority (CA).
13
13
14
14
**Handler-Based Architecture**
15
-
: You implement a custom handler class that extends [HTTPSProxyHandler](reference/https_proxy_handler.md)to define how requests and responses are processed.
15
+
: You implement a custom handler class. For most use cases, extend [HTTPSForwardProxyHandler](reference/https_forward_proxy_handler.md)which provides automatic request forwarding. For advanced control, use the lower-level [HTTPSProxyHandler](advanced-usage.md).
16
16
17
17
**Asyncio Native**
18
18
: Built using Python's asyncio framework for high-performance, non-blocking operations.
Copy file name to clipboardExpand all lines: docs/index.md
+2Lines changed: 2 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -18,6 +18,8 @@ It's a fundation layer for building your own proxy-based tools.
18
18
-**Certificate generation**: Dynamically generate and sign certificates for intercepted HTTPS traffic
19
19
-**Request/Response interception**: Modify, log, or block HTTP(S) traffic in real-time
20
20
-**Lightweight**: Pure Python implementation with only cryptography as a direct external dependency
21
+
-**Optional implementation of forward proxy**: The implementation to forward HTTP request can be replace in order to use different HTTP client implementation
0 commit comments