Skip to content

Comments

feat: add HTTP/2 WebSocket support (RFC 8441)#354

Draft
mcollina wants to merge 1 commit intomainfrom
feat/rfc-8441-http2-websocket
Draft

feat: add HTTP/2 WebSocket support (RFC 8441)#354
mcollina wants to merge 1 commit intomainfrom
feat/rfc-8441-http2-websocket

Conversation

@mcollina
Copy link
Member

Summary

  • Adds support for WebSocket over HTTP/2 using the Extended CONNECT Protocol (RFC 8441)
  • Automatically detects HTTP/2 servers and enables enableConnectProtocol
  • Wraps Fastify's stream handler to intercept WebSocket CONNECT requests
  • Creates WebSocket instances over HTTP/2 streams using ws.setSocket()
  • Handles client tracking for HTTP/2 WebSocket connections

Test plan

  • Added 4 new tests for HTTP/2 WebSocket in test/http2.test.js
  • Basic HTTP/2 WebSocket connection
  • Multiple concurrent WebSocket connections over single HTTP/2 connection
  • Mixed HTTP/2 and WebSocket traffic on same server
  • Client tracking with HTTP/2 WebSocket
  • All existing tests pass
  • 100% code coverage maintained

Closes #353

Implements WebSocket connections over HTTP/2 using the Extended CONNECT
Protocol (RFC 8441). This enables WebSocket communication over HTTP/2
streams when using Fastify with http2: true option.

Key changes:
- Detect HTTP/2 servers and enable enableConnectProtocol setting
- Intercept HTTP/2 stream events to handle WebSocket CONNECT requests
- Create WebSocket instances over HTTP/2 streams with proper frame masking
- Add client tracking support for HTTP/2 WebSocket connections
- Handle both HTTP/1.1 upgrade and HTTP/2 CONNECT protocols
- Ensure compatibility with existing HTTP/2 requests

Test coverage:
- Basic HTTP/2 WebSocket connection test
- Multiple concurrent WebSocket connections over single HTTP/2 connection
- Mixed HTTP/2 regular and WebSocket requests
- Client tracking functionality

Documentation:
- Added HTTP/2 Support section to README.md
- Included usage example with http2: true option
- Referenced RFC 8441 specification

Fixes #353
@mcollina
Copy link
Member Author

I'm not convinced we should support this due to websockets/ws#1458

@mcollina mcollina mentioned this pull request Jan 16, 2026
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.

Support RFC 8441

1 participant