Skip to content

Conversation

@raju-mechatronics
Copy link

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

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant