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

Copy link
Contributor

@aldas aldas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@aldas
Copy link
Contributor

aldas commented Jan 25, 2026

@raju-mechatronics you probably forgot to run tests in v5.

@raju-mechatronics
Copy link
Author

@aldas fixed it. In master it's context but in v5 it's Context.

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.

2 participants