fetchDedup tries peers then origin, deduplicating concurrent fetches. On success the body has been committed to local disk under cacheKey; the caller serves it by streaming from the file. Nothing here holds the body in memory.
(cacheKey string, r *http.Request, rangeHeader string)
| 356 | "upgrade": true, |
| 357 | } |
| 358 | |
| 359 | // cachePassthroughHeader is added only by duckgres's worker-local router. |
| 360 | // It selects the proxy's observable-but-uncached request path and is stripped |
| 361 | // before the origin request so it cannot affect S3 or a SigV4 request. |
| 362 | const cachePassthroughHeader = "X-Duckgres-Cache-Passthrough" |
| 363 | |
| 364 | func isInternalPropagationHeader(header string) bool { |
| 365 | return strings.EqualFold(header, "traceparent") || strings.EqualFold(header, "tracestate") |
| 366 | } |
| 367 | |
| 368 | // HandleProxy handles forward HTTP proxy requests from DuckDB httpfs. |
| 369 | // Expects absolute-form URIs (scheme + host + path in the request-line). |
| 370 | func (p *CacheProxy) HandleProxy(w http.ResponseWriter, r *http.Request) { |
| 371 | inflightRequests.Inc() |
| 372 | defer inflightRequests.Dec() |
| 373 | r = r.WithContext(otel.GetTextMapPropagator().Extract(r.Context(), propagation.HeaderCarrier(r.Header))) |
| 374 | |
| 375 | // HTTPS via CONNECT tunnel — we can't cache encrypted traffic, but we must |
| 376 | // still tunnel it so DuckDB can reach external HTTPS sources (e.g. |
| 377 | // read_parquet('https://datasets.clickhouse.com/...')) while |
| 378 | // http_proxy is set globally. |
| 379 | if r.Method == http.MethodConnect { |
| 380 | p.handleConnect(w, r) |
| 381 | return |
| 382 | } |
| 383 | |
| 384 | if r.URL.Scheme == "" || r.URL.Host == "" { |
| 385 | http.Error(w, "expected forward-proxy absolute-form URL", http.StatusBadRequest) |
| 386 | return |
| 387 | } |
| 388 | |
| 389 | // Non-GET (HEAD, etc.) is never cached — forward and return. |
no test coverage detected