Documentation
¶
Index ¶
- Constants
- Variables
- func DecodeQueryParams(values url.Values, v interface{}) error
- func EncodeQueryParams(v interface{}) (url.Values, error)
- func EscapePathValue(value string) string
- func FormDataPartHeader(fieldname, filename, contentType string) textproto.MIMEHeader
- func NewResponseWriter(w http.ResponseWriter, contentType string) io.Writer
- type ClientRawRecvStream
- type ClientRawSendStream
- type ClientRawStream
- type ClientRecvStream
- type ClientSendStream
- type ClientStream
- type Context
- type DialOptions
- type InStream
- type MethodHandlerFunc
- type MethodHolder
- type Middleware
- type OutStream
- type Params
- type Path
- type PathParam
- type RRPCError
- type RawInStream
- type RawOutStream
- type RawStream
- type ResponseInfo
- type ResponseObserver
- type Server
- func (s *Server) Observe(observers ...ResponseObserver)
- func (s *Server) RegisterModule(module ServerModule) error
- func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request)
- func (s *Server) SetOnRequest(fn func(w http.ResponseWriter, r *http.Request) error)
- func (s *Server) Use(middlewares ...Middleware)
- type ServerModule
- type ServiceHandler
- type StaticFilesHandler
- type Stream
- type UpgradeOptions
Constants ¶
const ContentTypeHeader = "Content-Type"
const MethodNameCtxKey = "rrpc-method"
const ServiceNameCtxKey = "rrpc-service"
Variables ¶
var ( ErrRrpcEndpoint = RRPCError{Code: 0, Name: "RrpcEndpoint", Message: "endpoint error", HTTPStatus: 400} ErrRrpcRequestFailed = RRPCError{Code: -1, Name: "RrpcRequestFailed", Message: "request failed", HTTPStatus: 400} ErrRrpcBadRoute = RRPCError{Code: -2, Name: "RrpcBadRoute", Message: "bad route", HTTPStatus: 404} ErrRrpcBadMethod = RRPCError{Code: -3, Name: "RrpcBadMethod", Message: "bad method", HTTPStatus: 405} ErrRrpcBadRequest = RRPCError{Code: -4, Name: "RrpcBadRequest", Message: "bad request", HTTPStatus: 400} ErrRrpcBadResponse = RRPCError{Code: -5, Name: "RrpcBadResponse", Message: "bad response", HTTPStatus: 500} ErrRrpcServerPanic = RRPCError{Code: -6, Name: "RrpcServerPanic", Message: "server panic", HTTPStatus: 500} ErrRrpcInternalError = RRPCError{Code: -7, Name: "RrpcInternalError", Message: "internal error", HTTPStatus: 500} ErrRrpcClientDisconnected = RRPCError{Code: -8, Name: "RrpcClientDisconnected", Message: "client disconnected", HTTPStatus: 400} )
RRPC errors
var DataMethods = []string{"POST", "PUT"}
Functions ¶
func DecodeQueryParams ¶
DecodeQueryParams decodes URL query parameters into a struct using JSON tags.
Each value is converted according to the type of the field it lands in, not by guessing from its text: a string field keeps "2024", "true" or "007" exactly as sent, a bool field accepts anything strconv.ParseBool does, and numeric fields parse as numbers. A value that doesn't parse as its field's type is passed through unconverted so the JSON decode reports it, which surfaces to the caller as an error (a 400 from generated handlers). Keys that match no field of v (or a v that isn't a struct pointer) fall back to guessing numeric/boolean values from their text.
Keys using bracket notation ("filters[name]=foo") are grouped into a nested map under the outer key ("filters": {"name": "foo"}) before unmarshaling — the encoding a map-typed field (e.g. a generated DatatableRequest.Filters map[string]string) arrives in, since a browser's URLSearchParams has no native nested-object representation. Only one level of nesting is supported (matching map[string]V fields); a key with more than one bracket pair (e.g. "a[b][c]") is not specially parsed.
func EncodeQueryParams ¶
EncodeQueryParams is the inverse of DecodeQueryParams: it turns a struct (or pointer to one) into URL query parameters using its JSON tags, so a value survives the round trip through DecodeQueryParams unchanged.
Fields JSON would omit (nil pointers, omitempty zero values) and null values are left out. A map[string]V field (or a struct of scalars, which JSON cannot tell apart from a map) becomes one level of bracket notation ("filters[name]=foo"). []byte fields are sent as the base64 text JSON uses for them. Slices and anything nested deeper than one level have no query-string form and return an error instead of being silently mangled - the rrpc validator rejects such fields for GET methods for the same reason.
func EscapePathValue ¶
EscapePathValue encodes value for safe inclusion in a URL path built from a "path"-typed parameter, which — unlike a "string"-typed one — may itself contain "/" separators that must be preserved rather than escaped away. Each segment between slashes is percent-encoded individually; the separators themselves are not.
func FormDataPartHeader ¶
func FormDataPartHeader(fieldname, filename, contentType string) textproto.MIMEHeader
FormDataPartHeader returns the MIME header a multipart bytes field's part should carry: the same Content-Disposition mime/multipart.Writer. CreateFormFile builds internally, but with contentType instead of its hardcoded "application/octet-stream" default - for generated clients that need to declare that part's own Content-Type (see @RequestContentType on a multipart method). Pass it to (*multipart.Writer).CreatePart in place of CreateFormFile.
func NewResponseWriter ¶
func NewResponseWriter(w http.ResponseWriter, contentType string) io.Writer
Types ¶
type ClientRawRecvStream ¶
func DialRawRecvStream ¶
func DialRawRecvStream(ctx context.Context, url string, opts DialOptions) (*ClientRawRecvStream, error)
func (*ClientRawRecvStream) Close ¶
func (d *ClientRawRecvStream) Close(code websocket.StatusCode, reason string) error
Close closes the underlying connection. Safe to call multiple times.
func (*ClientRawRecvStream) CloseGracefully ¶
func (d *ClientRawRecvStream) CloseGracefully() error
CloseGracefully closes the connection with a normal-closure status - the generated handler wrapper for every streaming method defers this once Upgrade succeeds, specifically so a handler that returns normally (all data sent, done) ends the connection with a proper WS close frame instead of leaving that to Context()'s fallback. That fallback (see Context's doc comment and upgrade's use of the request context) only exists to eventually reclaim a connection whose handler forgot to close it - it does so via CloseRead's background reader observing context cancellation, which lands on Conn's internal abrupt teardown, not a graceful close, and shows up client-side as a "closed abnormally" error even though every byte was already delivered. Safe to call multiple times, same as Close.
type ClientRawSendStream ¶
func DialRawSendStream ¶
func DialRawSendStream(ctx context.Context, url string, opts DialOptions) (*ClientRawSendStream, error)
func (*ClientRawSendStream) Close ¶
func (d *ClientRawSendStream) Close(code websocket.StatusCode, reason string) error
Close closes the underlying connection. Safe to call multiple times.
func (*ClientRawSendStream) CloseGracefully ¶
func (d *ClientRawSendStream) CloseGracefully() error
CloseGracefully closes the connection with a normal-closure status - the generated handler wrapper for every streaming method defers this once Upgrade succeeds, specifically so a handler that returns normally (all data sent, done) ends the connection with a proper WS close frame instead of leaving that to Context()'s fallback. That fallback (see Context's doc comment and upgrade's use of the request context) only exists to eventually reclaim a connection whose handler forgot to close it - it does so via CloseRead's background reader observing context cancellation, which lands on Conn's internal abrupt teardown, not a graceful close, and shows up client-side as a "closed abnormally" error even though every byte was already delivered. Safe to call multiple times, same as Close.
type ClientRawStream ¶
type ClientRawStream struct {
io.ReadWriter
// contains filtered or unexported fields
}
ClientRawStream, ClientRawSendStream, ClientRawRecvStream are the dialing counterparts of RawStream/RawInStream/RawOutStream, used for streaming methods whose direction is declared "bytes" rather than a struct type.
func DialRawStream ¶
func DialRawStream(ctx context.Context, url string, opts DialOptions) (*ClientRawStream, error)
func (*ClientRawStream) Close ¶
func (d *ClientRawStream) Close(code websocket.StatusCode, reason string) error
Close closes the underlying connection. Safe to call multiple times.
func (*ClientRawStream) CloseGracefully ¶
func (d *ClientRawStream) CloseGracefully() error
CloseGracefully closes the connection with a normal-closure status - the generated handler wrapper for every streaming method defers this once Upgrade succeeds, specifically so a handler that returns normally (all data sent, done) ends the connection with a proper WS close frame instead of leaving that to Context()'s fallback. That fallback (see Context's doc comment and upgrade's use of the request context) only exists to eventually reclaim a connection whose handler forgot to close it - it does so via CloseRead's background reader observing context cancellation, which lands on Conn's internal abrupt teardown, not a graceful close, and shows up client-side as a "closed abnormally" error even though every byte was already delivered. Safe to call multiple times, same as Close.
type ClientRecvStream ¶
type ClientRecvStream[Out any] struct { // contains filtered or unexported fields }
ClientRecvStream is the client side of "@OutputStream" - the client is the one receiving, so it only has Recv (with the same error-frame surfacing as ClientStream.Recv).
func DialRecvStream ¶
func DialRecvStream[Out any](ctx context.Context, url string, opts DialOptions) (*ClientRecvStream[Out], error)
func (*ClientRecvStream) Close ¶
func (d *ClientRecvStream) Close(code websocket.StatusCode, reason string) error
Close closes the underlying connection. Safe to call multiple times.
func (*ClientRecvStream) CloseGracefully ¶
func (d *ClientRecvStream) CloseGracefully() error
CloseGracefully closes the connection with a normal-closure status - the generated handler wrapper for every streaming method defers this once Upgrade succeeds, specifically so a handler that returns normally (all data sent, done) ends the connection with a proper WS close frame instead of leaving that to Context()'s fallback. That fallback (see Context's doc comment and upgrade's use of the request context) only exists to eventually reclaim a connection whose handler forgot to close it - it does so via CloseRead's background reader observing context cancellation, which lands on Conn's internal abrupt teardown, not a graceful close, and shows up client-side as a "closed abnormally" error even though every byte was already delivered. Safe to call multiple times, same as Close.
func (*ClientRecvStream) Context ¶
Context returns the connection-scoped context - use this, not the original request context, in a long-running Recv/Send loop.
func (*ClientRecvStream[Out]) Recv ¶
func (s *ClientRecvStream[Out]) Recv() (Out, error)
type ClientSendStream ¶
type ClientSendStream[In any] struct { // contains filtered or unexported fields }
ClientSendStream is the client side of "@InputStream" - the client is the one sending, so it only has Send.
func DialSendStream ¶
func DialSendStream[In any](ctx context.Context, url string, opts DialOptions) (*ClientSendStream[In], error)
func (*ClientSendStream) Close ¶
func (d *ClientSendStream) Close(code websocket.StatusCode, reason string) error
Close closes the underlying connection. Safe to call multiple times.
func (*ClientSendStream) CloseGracefully ¶
func (d *ClientSendStream) CloseGracefully() error
CloseGracefully closes the connection with a normal-closure status - the generated handler wrapper for every streaming method defers this once Upgrade succeeds, specifically so a handler that returns normally (all data sent, done) ends the connection with a proper WS close frame instead of leaving that to Context()'s fallback. That fallback (see Context's doc comment and upgrade's use of the request context) only exists to eventually reclaim a connection whose handler forgot to close it - it does so via CloseRead's background reader observing context cancellation, which lands on Conn's internal abrupt teardown, not a graceful close, and shows up client-side as a "closed abnormally" error even though every byte was already delivered. Safe to call multiple times, same as Close.
func (*ClientSendStream) Context ¶
Context returns the connection-scoped context - use this, not the original request context, in a long-running Recv/Send loop.
func (*ClientSendStream[In]) Send ¶
func (s *ClientSendStream[In]) Send(msg In) error
type ClientStream ¶
type ClientStream[In, Out any] struct { // contains filtered or unexported fields }
ClientStream, ClientSendStream, ClientRecvStream are the generated Go client's counterparts of Stream/InStream/OutStream - used by one Go program calling another rrpc-based Go service directly (via the generated *ServiceClientHandler methods), independent of the browser/TS client. Type parameter naming stays consistent with the .rrpc declaration regardless of which side's code you're reading (In is always the client->server type, Out always server->client) - only the available method set flips between server (accepting an inbound connection) and client (dialing an outbound one).
func DialStream ¶
func DialStream[In, Out any](ctx context.Context, url string, opts DialOptions) (*ClientStream[In, Out], error)
func (*ClientStream) Close ¶
func (d *ClientStream) Close(code websocket.StatusCode, reason string) error
Close closes the underlying connection. Safe to call multiple times.
func (*ClientStream) CloseGracefully ¶
func (d *ClientStream) CloseGracefully() error
CloseGracefully closes the connection with a normal-closure status - the generated handler wrapper for every streaming method defers this once Upgrade succeeds, specifically so a handler that returns normally (all data sent, done) ends the connection with a proper WS close frame instead of leaving that to Context()'s fallback. That fallback (see Context's doc comment and upgrade's use of the request context) only exists to eventually reclaim a connection whose handler forgot to close it - it does so via CloseRead's background reader observing context cancellation, which lands on Conn's internal abrupt teardown, not a graceful close, and shows up client-side as a "closed abnormally" error even though every byte was already delivered. Safe to call multiple times, same as Close.
func (*ClientStream) Context ¶
Context returns the connection-scoped context - use this, not the original request context, in a long-running Recv/Send loop.
func (*ClientStream[In, Out]) Recv ¶
func (s *ClientStream[In, Out]) Recv() (Out, error)
Recv reads the next server->client frame. A received {"error": ...} envelope surfaces here as a returned Go error (built from the same RRPCError shape the server sends) - the natural Go equivalent of the TS client's message-iterator throwing on an error frame.
func (*ClientStream[In, Out]) Send ¶
func (s *ClientStream[In, Out]) Send(msg In) error
type Context ¶
type Context struct {
// contains filtered or unexported fields
}
func NewContext ¶
func (*Context) Hijacked ¶
Hijacked reports whether this request's response has already been handled by a WebSocket upgrade attempt (see Upgrade*/UpgradeRaw* in websocket.go) - true both when the upgrade succeeded and when it was attempted but failed, since the underlying WebSocket library writes its own response to Response() in either case. Once true, Response() is no longer usable for a normal HTTP response - the server will not attempt to write a JSON error body for whatever error the handler eventually returns.
func (*Context) Response ¶
func (c *Context) Response() http.ResponseWriter
type DialOptions ¶
type DialOptions struct {
Subprotocols []string
}
DialOptions configures a client-side streaming connection - the dialing counterpart of UpgradeOptions. Bare today; grows a token/subprotocol option later if/when the generated non-streaming Go client adopts one, rather than inventing one speculatively here.
type InStream ¶
type InStream[In any] struct { // contains filtered or unexported fields }
InStream is a client->server-only typed message stream - "@InputStream". The server only receives; there's no Send/SendError - no existing "client sends a typed error to the server" concept to extend.
func UpgradeInStream ¶
func UpgradeInStream[In any](ctx *Context, opts UpgradeOptions) (*InStream[In], error)
func (*InStream) Close ¶
func (d *InStream) Close(code websocket.StatusCode, reason string) error
Close closes the underlying connection. Safe to call multiple times.
func (*InStream) CloseGracefully ¶
func (d *InStream) CloseGracefully() error
CloseGracefully closes the connection with a normal-closure status - the generated handler wrapper for every streaming method defers this once Upgrade succeeds, specifically so a handler that returns normally (all data sent, done) ends the connection with a proper WS close frame instead of leaving that to Context()'s fallback. That fallback (see Context's doc comment and upgrade's use of the request context) only exists to eventually reclaim a connection whose handler forgot to close it - it does so via CloseRead's background reader observing context cancellation, which lands on Conn's internal abrupt teardown, not a graceful close, and shows up client-side as a "closed abnormally" error even though every byte was already delivered. Safe to call multiple times, same as Close.
type MethodHandlerFunc ¶
type MethodHolder ¶
type MethodHolder struct {
Path *Path
Type string
ContentType string
HandlerFunc MethodHandlerFunc
}
type OutStream ¶
type OutStream[Out any] struct { // contains filtered or unexported fields }
OutStream is a server->client-only typed message stream - "@OutputStream". The server only sends; it has no typed Recv, but can still observe disconnect via Context() cancellation.
func UpgradeOutStream ¶
func UpgradeOutStream[Out any](ctx *Context, opts UpgradeOptions) (*OutStream[Out], error)
func (*OutStream) Close ¶
func (d *OutStream) Close(code websocket.StatusCode, reason string) error
Close closes the underlying connection. Safe to call multiple times.
func (*OutStream) CloseGracefully ¶
func (d *OutStream) CloseGracefully() error
CloseGracefully closes the connection with a normal-closure status - the generated handler wrapper for every streaming method defers this once Upgrade succeeds, specifically so a handler that returns normally (all data sent, done) ends the connection with a proper WS close frame instead of leaving that to Context()'s fallback. That fallback (see Context's doc comment and upgrade's use of the request context) only exists to eventually reclaim a connection whose handler forgot to close it - it does so via CloseRead's background reader observing context cancellation, which lands on Conn's internal abrupt teardown, not a graceful close, and shows up client-side as a "closed abnormally" error even though every byte was already delivered. Safe to call multiple times, same as Close.
type RRPCError ¶
type RRPCError struct {
Name string `json:"error"`
Code int `json:"code"`
Message string `json:"msg"`
Cause string `json:"cause,omitempty"`
HTTPStatus int `json:"-"`
// contains filtered or unexported fields
}
func (RRPCError) WithCauseString ¶
WithCauseString sets the cause from the Cause string field. Used after JSON unmarshaling to restore the error chain.
func (RRPCError) WithCausef ¶
type RawInStream ¶
func UpgradeRawInStream ¶
func UpgradeRawInStream(ctx *Context, opts UpgradeOptions) (*RawInStream, error)
func (*RawInStream) Close ¶
func (d *RawInStream) Close(code websocket.StatusCode, reason string) error
Close closes the underlying connection. Safe to call multiple times.
func (*RawInStream) CloseGracefully ¶
func (d *RawInStream) CloseGracefully() error
CloseGracefully closes the connection with a normal-closure status - the generated handler wrapper for every streaming method defers this once Upgrade succeeds, specifically so a handler that returns normally (all data sent, done) ends the connection with a proper WS close frame instead of leaving that to Context()'s fallback. That fallback (see Context's doc comment and upgrade's use of the request context) only exists to eventually reclaim a connection whose handler forgot to close it - it does so via CloseRead's background reader observing context cancellation, which lands on Conn's internal abrupt teardown, not a graceful close, and shows up client-side as a "closed abnormally" error even though every byte was already delivered. Safe to call multiple times, same as Close.
type RawOutStream ¶
func UpgradeRawOutStream ¶
func UpgradeRawOutStream(ctx *Context, opts UpgradeOptions) (*RawOutStream, error)
func (*RawOutStream) Close ¶
func (d *RawOutStream) Close(code websocket.StatusCode, reason string) error
Close closes the underlying connection. Safe to call multiple times.
func (*RawOutStream) CloseGracefully ¶
func (d *RawOutStream) CloseGracefully() error
CloseGracefully closes the connection with a normal-closure status - the generated handler wrapper for every streaming method defers this once Upgrade succeeds, specifically so a handler that returns normally (all data sent, done) ends the connection with a proper WS close frame instead of leaving that to Context()'s fallback. That fallback (see Context's doc comment and upgrade's use of the request context) only exists to eventually reclaim a connection whose handler forgot to close it - it does so via CloseRead's background reader observing context cancellation, which lands on Conn's internal abrupt teardown, not a graceful close, and shows up client-side as a "closed abnormally" error even though every byte was already delivered. Safe to call multiple times, same as Close.
type RawStream ¶
type RawStream struct {
io.ReadWriter
// contains filtered or unexported fields
}
RawStream, RawInStream, RawOutStream are the raw-byte-stream counterparts of Stream/InStream/OutStream, generated instead of the typed generics above when a streaming method's direction is declared with "bytes" rather than a struct type. Each embeds the corresponding stdlib interface directly via websocket.NetConn (which already handles buffering/chunking across WebSocket frame boundaries), so it can be passed straight into io.Copy, wrapped in a bufio.Scanner, or handed to any other io.Reader/io.Writer-consuming code.
func UpgradeRawStream ¶
func UpgradeRawStream(ctx *Context, opts UpgradeOptions) (*RawStream, error)
func (*RawStream) Close ¶
func (d *RawStream) Close(code websocket.StatusCode, reason string) error
Close closes the underlying connection. Safe to call multiple times.
func (*RawStream) CloseGracefully ¶
func (d *RawStream) CloseGracefully() error
CloseGracefully closes the connection with a normal-closure status - the generated handler wrapper for every streaming method defers this once Upgrade succeeds, specifically so a handler that returns normally (all data sent, done) ends the connection with a proper WS close frame instead of leaving that to Context()'s fallback. That fallback (see Context's doc comment and upgrade's use of the request context) only exists to eventually reclaim a connection whose handler forgot to close it - it does so via CloseRead's background reader observing context cancellation, which lands on Conn's internal abrupt teardown, not a graceful close, and shows up client-side as a "closed abnormally" error even though every byte was already delivered. Safe to call multiple times, same as Close.
type ResponseInfo ¶
type ResponseInfo struct {
// Route is the matched route's path template (service path + method
// path, e.g. "/hooks/{token}"), never the raw request path, so it is
// safe as a metrics label. It is "" when no route matched.
Route string
// Status is the HTTP status written (200 if the handler wrote none).
// For a hijacked (WebSocket) connection it is 101.
Status int
// Bytes is the number of response body bytes written.
Bytes int64
// Duration is the time spent in ServeHTTP.
Duration time.Duration
}
ResponseInfo describes one finished request, as reported to a ResponseObserver. It covers every response the server produced, including error responses and requests that matched no route.
type ResponseObserver ¶
type ResponseObserver func(r *http.Request, info ResponseInfo)
ResponseObserver is called once per request, after the response has been written. It must not block and must not touch the request's body or the ResponseWriter.
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
func (*Server) Observe ¶
func (s *Server) Observe(observers ...ResponseObserver)
Observe registers a ResponseObserver. Not safe to call concurrently with serving; register observers before the server starts.
func (*Server) RegisterModule ¶
func (s *Server) RegisterModule(module ServerModule) error
func (*Server) SetOnRequest ¶
func (*Server) Use ¶
func (s *Server) Use(middlewares ...Middleware)
type ServerModule ¶
type ServerModule interface {
Name() string
Services() map[string]ServiceHandler
}
type ServiceHandler ¶
type ServiceHandler interface {
Name() string
Path() *Path
Methods() []MethodHolder
}
type StaticFilesHandler ¶
type StaticFilesHandler struct {
// contains filtered or unexported fields
}
func NewStaticFilesHandler ¶
func NewStaticFilesHandler(pathParamName string, fs fs.FS, baseDir string) *StaticFilesHandler
func (*StaticFilesHandler) ServeStatic ¶
func (h *StaticFilesHandler) ServeStatic(ctx *Context, w io.Writer) error
type Stream ¶
type Stream[In, Out any] struct { // contains filtered or unexported fields }
Stream is a bidirectional typed message stream - "@Stream".
func UpgradeStream ¶
func UpgradeStream[In, Out any](ctx *Context, opts UpgradeOptions) (*Stream[In, Out], error)
func (*Stream) Close ¶
func (d *Stream) Close(code websocket.StatusCode, reason string) error
Close closes the underlying connection. Safe to call multiple times.
func (*Stream) CloseGracefully ¶
func (d *Stream) CloseGracefully() error
CloseGracefully closes the connection with a normal-closure status - the generated handler wrapper for every streaming method defers this once Upgrade succeeds, specifically so a handler that returns normally (all data sent, done) ends the connection with a proper WS close frame instead of leaving that to Context()'s fallback. That fallback (see Context's doc comment and upgrade's use of the request context) only exists to eventually reclaim a connection whose handler forgot to close it - it does so via CloseRead's background reader observing context cancellation, which lands on Conn's internal abrupt teardown, not a graceful close, and shows up client-side as a "closed abnormally" error even though every byte was already delivered. Safe to call multiple times, same as Close.
func (*Stream) Context ¶
Context returns the connection-scoped context - use this, not the original request context, in a long-running Recv/Send loop.
func (*Stream[In, Out]) Recv ¶
Recv reads and JSON-decodes the next client->server frame. A peer close surfaces as an error - use websocket.CloseStatus(err) to distinguish a normal close from an abnormal one, same as using coder/websocket directly.
type UpgradeOptions ¶
type UpgradeOptions struct {
Subprotocols []string
}
UpgradeOptions configures a WebSocket upgrade. Leaving Subprotocols nil does NOT mean "no subprotocol negotiation" - if the client's handshake offered any (e.g. maf/rrpc-auth's "bearer, <token>" trick for carrying an auth token, since a browser's native WebSocket constructor can't set arbitrary headers on the handshake request), upgrade mirrors them back automatically. This isn't optional politeness: per RFC 6455 §4.1, a client that offered subprotocols MUST fail the connection if the server's response doesn't select one of them - every real implementation (browsers, the "ws" npm package, Go's x/net/websocket) enforces this, even though nothing in a raw HTTP Upgrade response makes the omission look wrong (curl, for instance, won't complain). Set Subprotocols explicitly only when a handler needs to require or choose among specific values itself.