fix: validate Connection header in IsWebSocket() [per RFC 6455] by raju-mechatronics · Pull Request #2875 · labstack/echo
Description
This PR fixes the IsWebSocket() function to properly validate WebSocket upgrade requests according to RFC 6455 specification.
Problem
The current implementation only checks the Upgrade header but ignores the Connection header requirement specified in RFC 6455 Section 1.3. A valid WebSocket upgrade request must have both headers present with specific values.
Solution
Updated IsWebSocket() to validate both required headers:
Upgrade: websocket(case-insensitive)Connection: upgrade(case-insensitive, may contain other values)
Changes
- Modified
IsWebSocket()incontext.goto check both headers - Updated
TestContext_IsWebSocket()incontext_test.gowith additional test cases - Added test case for missing/invalid
Connectionheader
Testing
All existing tests pass, including new test cases that verify:
- Valid WebSocket requests with both headers present
- Case-insensitive header matching
- Invalid requests missing the
Connectionheader - Invalid requests with
Connection: close