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() in context.go to check both headers
  • Updated TestContext_IsWebSocket() in context_test.go with additional test cases
  • Added test case for missing/invalid Connection header

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 Connection header
  • Invalid requests with Connection: close

RFC Reference

RFC 6455 - The WebSocket Protocol