1.2 KiB
1.2 KiB
Contract: Host 路由 + 缓存代理
Request Flow
- Client sends HTTP request to
http://<listen-host>:<port>/<path>withHost: <hub-domain>. - Fiber middleware resolves HubRoute; if missing → 404 JSON
{ "error": "host_unmapped" }. - Proxy handler checks disk cache key =
<hub-name>/<path>. - Cache hit (Valid): stream file to client with stored headers.
- Cache stale/miss: build upstream request
Upstream + path, attachIf-None-Match/If-Modified-Sincewhen available, stream response back; on 200 store body to cache.
Required Headers
- Host (required) → determines Hub.
X-Any-Hub-Upstream(response) – actual upstream URL (debugging).X-Any-Hub-Cache-Hit(response) –true/false.X-Request-ID(response) – correlation id for logs.
Error Codes
| Scenario | Status | Body |
|---|---|---|
| Host 未配置 | 404 | { "error": "host_unmapped" } |
| 上游 4xx/5xx | mirror | 上游 body 原样透传 |
| 缓存写入失败 | 502 | { "error": "cache_write_failed" } |
Logging Fields
{
"action": "proxy",
"hub": "docker",
"domain": "docker.hub.local",
"cache_hit": true,
"upstream_status": 200,
"elapsed_ms": 123,
"error": ""
}