PhoenixWebTransport.ConnectInfo (phoenix_wtransport v0.1.0)

Copy Markdown View Source

Extracts connect_info and auth_token credentials for Phoenix.Socket.Transport with full parity for non-cookie HTTP/3 WebTransport CONNECT upgrades.

Supported :connect_info keys:

  • :peer_data - %{address: ip, port: port, ssl_cert: ...}
  • :uri - %URI{scheme: "https", ...} built from path, query, and :authority
  • :user_agent - value of "user-agent" header
  • :x_headers - all request headers starting with "x-" (lowercased names)
  • :trace_context_headers - "traceparent" / "tracestate" headers
  • :auth_token - decoded token from wt-protocol / sec-websocket-protocol header or a pre-join :auth frame (base64url.bearer.phx.<token>)
  • {:session, _} - always %{} on WebTransport (credentials: "omit" omits cookies, and Phoenix.LiveView.Channel rejects %{session: nil} as stale; use PhoenixWebTransport.Token + PhoenixWebTransport.Plug for session claims)
  • {key, val} - arbitrary custom key/value pairs passed through unchanged

Summary

Functions

Builds the connect_info map for socket.connect/1 based on configured keys.

Decodes an auth_token credential from either a "base64url.bearer.phx.<b64>" string (as emitted by phoenix.js) or a raw token binary when explicitly sent in a pre-join :auth frame.

Extracts an optional Phoenix auth_token from CONNECT subprotocol headers ("wt-protocol" or "sec-websocket-protocol").

Finds the first header value matching lowercase name.

Types

headers()

@type headers() :: [{binary(), binary()}]

Functions

build(req, socket_opts, auth_token \\ nil)

@spec build(map(), keyword(), binary() | nil) :: map()

Builds the connect_info map for socket.connect/1 based on configured keys.

decode_auth_token(raw, opts \\ [])

@spec decode_auth_token(binary(), keyword()) :: {:ok, binary()} | :error

Decodes an auth_token credential from either a "base64url.bearer.phx.<b64>" string (as emitted by phoenix.js) or a raw token binary when explicitly sent in a pre-join :auth frame.

extract_header_auth_token(headers)

@spec extract_header_auth_token(headers()) :: {:ok, binary()} | :none | :error

Extracts an optional Phoenix auth_token from CONNECT subprotocol headers ("wt-protocol" or "sec-websocket-protocol").

header_value(headers, name)

@spec header_value(headers(), binary()) :: binary() | nil

Finds the first header value matching lowercase name.