MCPcopy Create free account
hub / github.com/PostHog/duckgres / fetchDedup

Method fetchDedup

cmd/cache-proxy/proxy.go:358–386  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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.
362const cachePassthroughHeader = "X-Duckgres-Cache-Passthrough"
363
364func 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).
370func (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.

Callers 1

HandleProxyMethod · 0.95

Calls 8

fetchOriginMethod · 0.95
originFetchOutcomeFunction · 0.85
DoMethod · 0.80
FetchFromPeersMethod · 0.80
PutStreamMethod · 0.80
AddMethod · 0.80
StartMethod · 0.45
ContextMethod · 0.45

Tested by

no test coverage detected