GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - c2FmZQ/websocket: Fork of gorilla/websocket with server-side WebSocket over HTTP/2 (RFC 8441) and HTTP/3 (RFC 9220). Upgrader.Upgrade returns the same *websocket.Conn for HTTP/1.1, HTTP/2 and HTTP/3. No extra dependencies.

BranchesTags
Open more actions menu
 
 

Latest commit

 

History

372 Commits
372 Commits

Folders and files

NameName
Last commit message
Last commit date
.github/workflows
.github/workflows
 
 
examples
examples
 
 
h2xconnect
h2xconnect
 
 
internal/h3test
internal/h3test
 
 
.gitignore
.gitignore
 
 
.goversion
.goversion
 
 
AUTHORS
AUTHORS
 
 
LICENSE
LICENSE
 
 
README.md
README.md
 
 
client.go
client.go
 
 
client_proxy_server_test.go
client_proxy_server_test.go
 
 
client_server_test.go
client_server_test.go
 
 
client_test.go
client_test.go
 
 
compression.go
compression.go
 
 
compression_test.go
compression_test.go
 
 
conn.go
conn.go
 
 
conn_broadcast_test.go
conn_broadcast_test.go
 
 
conn_test.go
conn_test.go
 
 
doc.go
doc.go
 
 
example_test.go
example_test.go
 
 
go.mod
go.mod
 
 
go.sum
go.sum
 
 
join.go
join.go
 
 
join_test.go
join_test.go
 
 
json.go
json.go
 
 
json_test.go
json_test.go
 
 
mask.go
mask.go
 
 
mask_safe.go
mask_safe.go
 
 
mask_test.go
mask_test.go
 
 
prepared.go
prepared.go
 
 
prepared_test.go
prepared_test.go
 
 
proxy.go
proxy.go
 
 
race_test.go
race_test.go
 
 
server.go
server.go
 
 
server_test.go
server_test.go
 
 
stream_conn.go
stream_conn.go
 
 
stream_conn_test.go
stream_conn_test.go
 
 
util.go
util.go
 
 
util_test.go
util_test.go
 
 

Repository files navigation

Tests Go Reference

WebSocket (github.com/c2FmZQ/websocket)

github.com/c2FmZQ/websocket is a fork of gorilla/websocket that adds server-side support for:

  • WebSocket over HTTP/2 (RFC 8441 Extended CONNECT, including cleartext h2c)
  • WebSocket over HTTP/3 (RFC 9220 Extended CONNECT, compatible with quic-go/http3)

Upgrader.Upgrade returns a concrete *websocket.Conn across HTTP/1.1, HTTP/2, and HTTP/3, preserving drop-in API compatibility with gorilla/websocket—including subprotocol negotiation, permessage-deflate compression (RFC 7692), PreparedMessage, WriteBufferPool, and JSON helpers—with no additional runtime dependencies.

Installation

go get github.com/c2FmZQ/websocket

HTTP/2 & HTTP/3 Server Notes

  1. Enabling Extended CONNECT in Go's net/http (HTTP/2): Go's standard library net/http server disables RFC 8441 (SETTINGS_ENABLE_CONNECT_PROTOCOL) by default starting in Go 1.24.

    • Go 1.28+ (golang/go@e29e95265674, go.dev/issue/53208): Enable Extended CONNECT per server via http.HTTP2Config.EnableConnectProtocol (not yet in a released Go version as of Go 1.27):

      srv := &http.Server{
          Handler: mux,
          HTTP2: &http.HTTP2Config{
              EnableConnectProtocol: true,
          },
      }
    • Go 1.24–1.27: HTTP2Config.EnableConnectProtocol is not yet available, and http2xconnect cannot be set via //go:debug. Set GODEBUG=http2xconnect=1 in the environment at process startup, or import the h2xconnect helper package before any package that imports net/http:

      import (
          _ "github.com/c2FmZQ/websocket/h2xconnect"
      )

    (quic-go/http3.Server advertises SETTINGS_ENABLE_CONNECT_PROTOCOL = 1 by default.)

  2. Route registration: HTTP/1.1 WebSocket handshakes use GET, whereas HTTP/2 and HTTP/3 Extended CONNECT handshakes use CONNECT. When using method-specific http.ServeMux patterns, register both:

    mux.HandleFunc("GET /ws", handleWS)
    mux.HandleFunc("CONNECT /ws", handleWS)
  3. Handler lifetime (differs from gorilla/websocket): Over HTTP/2 and HTTP/3, the underlying stream is tied to the lifetime of http.Handler.ServeHTTP. The common gorilla pattern of starting read/write goroutines and returning from the handler does not work. Keep ServeHTTP active for the duration of the WebSocket session and close the connection before returning. Upgrader.Serve does both:

    func handleWS(w http.ResponseWriter, r *http.Request) {
        upgrader.Serve(w, r, nil, func(conn *websocket.Conn) {
            // Read/write using conn. The connection is closed when this returns.
        })
    }

    After Close returns, the connection's methods return net.ErrClosed, so goroutines that still hold it are safe. Returning from the handler without calling Close while another goroutine uses the connection is a data race with the HTTP server.

  4. Middleware: Any middleware that wraps http.ResponseWriter must implement Unwrap() http.ResponseWriter so that http.ResponseController can reach the stream's deadlines and flushing. Without deadlines, a peer could block the connection forever, so Upgrade rejects HTTP/2 and HTTP/3 requests with 500 Internal Server Error when they are unavailable.

License

BSD-2-Clause (see LICENSE).

About

Fork of gorilla/websocket with server-side WebSocket over HTTP/2 (RFC 8441) and HTTP/3 (RFC 9220). Upgrader.Upgrade returns the same *websocket.Conn for HTTP/1.1, HTTP/2 and HTTP/3. No extra dependencies.

Topics

gogolanggorilla-websockethttp2http3quicrfc8441rfc9220websocket

Resources

Readme
License
Activity
Custom properties

Stars

1 star

Watchers

1 watching

Forks

0 forks
Report repository

Releases

Contributors

Languages

You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.