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

Function TestForwardUncachedPreservesMethod

cmd/cache-proxy/proxy_test.go:1364–1383  ·  view source on GitHub ↗

TestForwardUncachedPreservesMethod walks every method that hits the non-GET path and checks the origin saw the same method. Ensures we don't accidentally specialise on PUT/POST and break HEAD/DELETE/etc.

(t *testing.T)

Source from the content-addressed store, hash-verified

1362}
1363
1364// TestForwardUncachedStripsHopByHopBothDirections verifies that
1365// hop-by-hop headers (per RFC 7230 §6.1) are NOT forwarded in either
1366// direction. Forwarding hop-by-hop headers can confuse origin / client
1367// parsers — Connection, Keep-Alive, TE, Trailers, Transfer-Encoding,
1368// Upgrade, Proxy-Authorization, Proxy-Authenticate.
1369func TestForwardUncachedStripsHopByHopBothDirections(t *testing.T) {
1370 proxy := newTestProxy(t)
1371
1372 var originSawConnection, originSawKeepAlive string
1373 _, originURL := newTestServer(t, func(w http.ResponseWriter, r *http.Request) {
1374 originSawConnection = r.Header.Get("Connection")
1375 originSawKeepAlive = r.Header.Get("Keep-Alive")
1376 w.Header().Set("Connection", "should-not-leak")
1377 w.Header().Set("Keep-Alive", "timeout=5")
1378 w.Header().Set("X-Allowed", "yes")
1379 w.WriteHeader(http.StatusOK)
1380 })
1381
1382 req := httptest.NewRequest(http.MethodPut, originURL+"/b/k", bytes.NewReader([]byte("x")))
1383 req.Host = req.URL.Host
1384 req.ContentLength = 1
1385 req.Header.Set("Connection", "close")
1386 req.Header.Set("Keep-Alive", "timeout=5")

Callers

nothing calls this directly

Calls 4

newTestProxyFunction · 0.85
newTestServerFunction · 0.85
HandleProxyMethod · 0.80
RunMethod · 0.65

Tested by

no test coverage detected