From 04c494cb00cb97bc742d6f1caecfcb41e78f17b8 Mon Sep 17 00:00:00 2001 From: SapirBaruch Date: Tue, 2 Jun 2026 21:09:56 +0300 Subject: [PATCH] test: fix TestNormalizeWebsocketHeadersSurvivesCopyHeader assertion MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit http.Header.Get re-canonicalizes its argument via CanonicalHeaderKey, so rebuilt.Get("Sec-WebSocket-Key") looks up the Go-canonical form "Sec-Websocket-Key" — the key normalizeWebsocketHeaders just deleted. Use a direct map lookup instead to assert the RFC 6455 key is present. --- modules/caddyhttp/reverseproxy/websocket_test.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/modules/caddyhttp/reverseproxy/websocket_test.go b/modules/caddyhttp/reverseproxy/websocket_test.go index ef2b9e398..fc626c2ee 100644 --- a/modules/caddyhttp/reverseproxy/websocket_test.go +++ b/modules/caddyhttp/reverseproxy/websocket_test.go @@ -97,8 +97,9 @@ func TestNormalizeWebsocketHeadersSurvivesCopyHeader(t *testing.T) { // The fix: call normalizeWebsocketHeaders after the rebuild. normalizeWebsocketHeaders(rebuilt) - // RFC 6455 form must be present. - if v := rebuilt.Get("Sec-WebSocket-Key"); v == "" { + // RFC 6455 form must be present (direct map lookup — .Get() re-canonicalizes + // to "Sec-Websocket-Key" and would miss the corrected key). + if _, ok := rebuilt["Sec-WebSocket-Key"]; !ok { t.Error("Sec-WebSocket-Key missing after normalize; WebSocket upgrade will fail") } // Lowercase form must be gone.