Skip to content

fix(resp): correct ConnectionUpgrade to check for Upgrade instead of keep-alive - #1537

Open
lxcxjxhx wants to merge 1 commit into
cloudwego:mainfrom
lxcxjxhx:fix/connection-upgrade-check
Open

lxcxjxhx wants to merge 1 commit into
cloudwego:mainfrom
lxcxjxhx:fix/connection-upgrade-check

Conversation

@lxcxjxhx

Copy link
Copy Markdown

What

Fix ConnectionUpgrade() in resp/header.go which was incorrectly checking for keep-alive instead of Upgrade in the Connection header.

Why

The function name and comment clearly state it should check for Connection: Upgrade, but the implementation was using bytestr.StrKeepAlive instead of bytestr.StrUpgrade.

This bug affects WebSocket support: when a response has Connection: Upgrade (as in WebSocket handshakes), ConnectionUpgrade() returns false, causing the code at line 204 to incorrectly set Transfer-Encoding: identity and close the connection.

Conversely, regular keep-alive responses would incorrectly trigger the upgrade path.

Changes

  • resp/header.go: change bytestr.StrKeepAlive to bytestr.StrUpgrade in ConnectionUpgrade()

Testing

go test ./pkg/protocol/http1/resp/...

All existing tests pass. This is a one-line bug fix.

@CLAassistant

CLAassistant commented Aug 23, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

…keep-alive

ConnectionUpgrade() was checking for the "keep-alive" value instead of
"Upgrade" in the Connection header. This caused WebSocket upgrade
responses to be incorrectly identified, potentially breaking WebSocket
support by setting Transfer-Encoding: identity and closing the connection.

Fix by using bytestr.StrUpgrade instead of bytestr.StrKeepAlive.
@lxcxjxhx
lxcxjxhx force-pushed the fix/connection-upgrade-check branch from a459cbe to 3672c5d Compare November 7, 2026 13:36
@lxcxjxhx

lxcxjxhx commented Nov 7, 2026

Copy link
Copy Markdown
Author

Rebased onto the current main so CI runs on today's toolchain.

The red checks on the previous head were both pkg/common/compress assertions, not this change:

--- FAIL: TestCompressAppendGzipBytesLevel
--- FAIL: TestCompressWriteGzipLevel
FAIL	github.com/cloudwego/hertz/pkg/common/compress

This PR touches one line in pkg/protocol/http1/resp/header.go, which the compress package does not import; the failures date from the 2026-08-24 run, and main's own Unit Tests have been green since. The behavioural check for the change is that ConnectionUpgrade now matches the client-side counterpart at pkg/protocol/http1/client.go:756, which already compares against bytestr.StrUpgrade.

Not run locally: this host has no Go toolchain, so the evidence is the rebased diff plus the existing test that covers the header path.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants