Documentation ¶
Overview ¶
Package noiseconn contains an internal-only wrapper around controlbase.Conn that properly handles the early payload sent by the server before the HTTP/2 session begins.
See the documentation on the Conn type for more details.
Index ¶
- Constants
- type Conn
- func (c *Conn) CanTakeNewRequest() bool
- func (c *Conn) Close() error
- func (c *Conn) GetEarlyPayload(ctx context.Context) (*tailcfg.EarlyNoise, error)
- func (c *Conn) Read(p []byte) (n int, err error)
- func (c *Conn) ReserveNewRequest(ctx context.Context) (bool, *tailcfg.EarlyNoise, error)
- func (c *Conn) RoundTrip(r *http.Request) (*http.Response, error)
Constants ¶
const EarlyPayloadMagic = "\xff\xff\xffTS"
EarlyPayloadMagic is the 5-byte magic prefix that indicates an early payload.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Conn ¶
type Conn struct { *controlbase.Conn // contains filtered or unexported fields }
Conn is a wrapper around controlbase.Conn.
It allows attaching an ID to a connection to allow cleaning up references in the pool when the connection is closed, properly handles an optional "early payload" that's sent prior to beginning the HTTP/2 session, and provides a way to return a connection to a pool when the connection is closed.
func New ¶
func New(conn *controlbase.Conn, h2t *http2.Transport, connID int, onClose func(int)) (*Conn, error)
New creates a new Conn that wraps the given controlbase.Conn.
h2t is the HTTP/2 transport to use for the connection; a new http2.ClientConn will be created that reads from the returned Conn.
connID should be a unique ID for this connection. When the Conn is closed, the onClose function will be called with the connID if it is non-nil.
func (*Conn) CanTakeNewRequest ¶
CanTakeNewRequest reports whether the underlying HTTP/2 connection can take a new request, meaning it has not been closed or received or sent a GOAWAY.
func (*Conn) GetEarlyPayload ¶
GetEarlyPayload waits for the early Noise payload to arrive. It may return (nil, nil) if the server begins HTTP/2 without one.
It is safe to call this multiple times; all callers will block until the early Noise payload is ready (if any) and will return the same result for the lifetime of the Conn.
func (*Conn) Read ¶
Read is basically the same as controlbase.Conn.Read, but it first reads the "early payload" header from the server which may or may not be present, depending on the server.
func (*Conn) ReserveNewRequest ¶
ReserveNewRequest will reserve a new concurrent request on the connection.
It returns whether the reservation was successful, and any early Noise payload if present. If a reservation was not successful, it will return false and nil for the early payload.