Skip to content

Commit ffba2c2

Browse files
committed
fix: Problems with ignored headers removed
1 parent 3a6de65 commit ffba2c2

4 files changed

Lines changed: 366 additions & 13 deletions

File tree

msgtausch-srv/proxy/http_interceptor.go

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1004,14 +1004,12 @@ func removeHopByHopHeaders(header http.Header) {
10041004
// Check if this is a WebSocket upgrade request
10051005
isWebSocketUpgrade := strings.ToLower(header.Get("Upgrade")) == "websocket"
10061006

1007-
// List of hop-by-hop headers from RFC 2616
1007+
// According to RFC 7230, only proxy-specific headers should be removed
1008+
// We preserve Transfer-Encoding, TE, Trailer, and Keep-Alive for proper HTTP semantics
10081009
hopByHopHeaders := []string{
1009-
"Keep-Alive",
10101010
"Proxy-Authenticate",
10111011
"Proxy-Authorization",
1012-
"TE",
1013-
"Trailers",
1014-
"Transfer-Encoding",
1012+
// Note: Keep-Alive, TE, Trailers, and Transfer-Encoding are preserved
10151013
}
10161014

10171015
// For WebSocket upgrades, preserve Connection and Upgrade headers

msgtausch-srv/proxy/proxy.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -971,14 +971,14 @@ func (p *Server) forwardRequest(w http.ResponseWriter, r *http.Request, client *
971971
logger.DebugCtx(ctx, "Detected proxied WebSocket request to %s", targetURL)
972972
}
973973

974+
// According to RFC 7230, proxy-specific headers should be removed,
975+
// but we preserve Transfer-Encoding, TE, Trailer, and Keep-Alive for proper HTTP semantics
974976
skip := map[string]struct{}{
975977
"Proxy-Connection": {},
976-
"Keep-Alive": {},
977978
"Proxy-Authenticate": {},
978979
"Proxy-Authorization": {},
979-
"Te": {},
980-
"Trailer": {},
981-
"Transfer-Encoding": {},
980+
// Note: Keep-Alive, TE, Trailer, and Transfer-Encoding are preserved
981+
// to maintain proper HTTP/1.1 connection and transfer semantics
982982
}
983983

984984
isWebSocketConnection := isWebSocketRequest || isProxiedWebSocket

msgtausch-srv/proxy/proxy_basic_test.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -409,16 +409,15 @@ func TestHTTP2ViaConnect(t *testing.T) {
409409
// TestForwardRequestHeaderSkipping verifies that hop-by-hop and proxy-specific headers
410410
// are correctly skipped when forwarding requests.
411411
func TestForwardRequestHeaderSkipping(t *testing.T) {
412+
// Only proxy-specific headers should be skipped, per RFC 7230
413+
// Transfer-Encoding, TE, Trailer, and Keep-Alive are preserved for proper HTTP semantics
412414
skippedHeaders := map[string]struct{}{
413415
"Proxy-Connection": {},
414416
"Connection": {},
415-
"Keep-Alive": {},
416417
"Proxy-Authenticate": {},
417418
"Proxy-Authorization": {},
418-
"Te": {},
419-
"Trailer": {},
420-
"Transfer-Encoding": {},
421419
"Upgrade": {},
420+
// Note: Keep-Alive, TE, Trailer, and Transfer-Encoding are no longer skipped
422421
}
423422

424423
// Create a test HTTP server that echoes received headers

0 commit comments

Comments
 (0)