Skip to content

Commit 02e81b2

Browse files
committed
v0.3.0
1 parent 99ee414 commit 02e81b2

2 files changed

Lines changed: 15 additions & 2 deletions

File tree

README.md

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ A robust, streaming-capable reverse proxy for FastAPI/Starlette with built-in **
1111
- **Unified Load Balancing**: Standard Round-Robin or Smart routing using a single utility.
1212
- **Latency-Based Routing**: Automatically routes traffic to the fastest healthy server (HEAD probe).
1313
- **Advanced Overrides**: Granular control over headers, body, and HTTP methods.
14+
- **Smart Error Mapping**: Automatically converts upstream connection failures into standard HTTP 502 (Bad Gateway) and 504 (Gateway Timeout) responses.
15+
- **Resilient Handshakes**: Customizable `open_timeout` for WebSockets to prevent proxy hangs during backend connection attempts.
1416
- **Version Agnostic**: Automatically handles `websockets` library version differences (12.0+ vs Legacy).
1517

1618
## Quick Start
@@ -43,18 +45,28 @@ async def index(req: Request):
4345

4446
```
4547

48+
## 🛡️ Resilience & Error Handling
49+
50+
Error Handlingfastapi-reverse-proxy transforms upstream crashes into meaningful HTTPException responses (e.g., 502 Bad Gateway or 504 Gateway Timeout).
51+
52+
This allows you to implement custom failover logic, retry mechanisms, or specific error pages.
53+
54+
For a full implementation of a primary-to-backup failover system, see the [example](https://github.com/tfsantos05/fastapi-reverse-proxy/tree/main/examples/02_http_errors.py).
55+
4656
## Advanced Examples:
4757

48-
Check [examples](https://github.com/tfsantos05/fastapi-reverse-proxy/blob/main/examples) for full examples, including
58+
Check [examples](https://github.com/tfsantos05/fastapi-reverse-proxy/tree/main/examples) for full examples, including:
4959
- **Websocket Proxy**
5060
- **Socket.IO Proxy**
61+
- **Error Handling & Failover** (`examples/error_handling_example.py`)
5162

5263
## Advanced Proxying
5364

5465
The `proxy_pass` function and `LoadBalancer.proxy_pass` provide deep customization for upstream requests:
5566

5667
| Parameter | Type | Description |
5768
| :--- | :--- | :--- |
69+
| `timeout` | `float` | Total request timeout in seconds (Default: `60.0`). |
5870
| `method` | `str` | Force a specific HTTP method (e.g., `"POST"`). |
5971
| `override_body` | `bytes` | Send custom data instead of the incoming request body. |
6072
| `additional_headers` | `dict` | Append custom headers to the proxied request. |
@@ -90,6 +102,7 @@ The library implements "deferred negotiation" for WebSockets:
90102
2. It establishes an upstream connection first.
91103
3. Once the upstream accepts a protocol, the proxy calls `websocket.accept(subprotocol=...)` back to the client.
92104
4. This ensures the entire tunnel (Client <-> Proxy <-> Upstream) uses the same negotiated protocol.
105+
5. **Handshake Timeout**: Supports a customizable `timeout` parameter (default `10.0s`) to prevent hangs if the backend is unresponsive.
93106

94107
## Robustness & Safety
95108

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
44

55
[project]
66
name = "fastapi-reverse-proxy"
7-
version = "0.2.0"
7+
version = "0.3.0"
88
authors = [
99
{ name="Tomás", email="tomas@suricatingss.xyz" },
1010
]

0 commit comments

Comments
 (0)