Documentation
¶
Overview ¶
Package http2 implements the HTTP/2 protocol.
This package is low-level and intended to be used directly by very few people. Most users will use it indirectly through the automatic use by the net/http package (from Go 1.6 and later). For use in earlier Go versions see ConfigureServer. (Transport support requires Go 1.6 or later)
See https://http2.github.io/ for more information on HTTP/2.
Index ¶
- Constants
- Variables
- type ClientConn
- func (cc *ClientConn) CanTakeNewRequest() bool
- func (cc *ClientConn) Close() error
- func (cc *ClientConn) NetworkIdleTime() time.Duration
- func (cc *ClientConn) Ping(ctx context.Context) error
- func (cc *ClientConn) ReserveNewRequest() bool
- func (cc *ClientConn) Retire(ctx context.Context, payload *[8]byte, goAway bool)
- func (cc *ClientConn) RoundTrip(req *ClientRequest) (*ClientResponse, error)
- func (cc *ClientConn) SetDoNotReuse()
- func (cc *ClientConn) Shutdown(ctx context.Context) error
- func (cc *ClientConn) State() ClientConnState
- type ClientConnState
- type ClientRequest
- type ClientResponse
- type Config
- type ConnState
- type ConnectionCloseInfo
- type ConnectionCloseOptions
- type ConnectionError
- type ConnectionErrorInfo
- type ContinuationFrame
- type DataFrame
- type ErrCode
- type Fingerprint
- type Flags
- type Frame
- type FrameHeader
- type FrameType
- type FrameWriteRequest
- type Framer
- func (fr *Framer) ErrorDetail() error
- func (fr *Framer) ReadFrame() (Frame, error)
- func (fr *Framer) ReadFrameForHeader(fh FrameHeader) (Frame, error)
- func (fr *Framer) ReadFrameHeader() (FrameHeader, error)
- func (fr *Framer) SetMaxReadFrameSize(v uint32)
- func (fr *Framer) SetReuseFrames()
- func (f *Framer) WriteContinuation(streamID uint32, endHeaders bool, headerBlockFragment []byte) error
- func (f *Framer) WriteData(streamID uint32, endStream bool, data []byte) error
- func (f *Framer) WriteDataPadded(streamID uint32, endStream bool, data, pad []byte) error
- func (f *Framer) WriteGoAway(maxStreamID uint32, code ErrCode, debugData []byte) error
- func (f *Framer) WriteHeaders(p HeadersFrameParam) error
- func (f *Framer) WritePing(ack bool, data [8]byte) error
- func (f *Framer) WritePriority(streamID uint32, p PriorityParam) error
- func (f *Framer) WritePriorityUpdate(streamID uint32, priority string) error
- func (f *Framer) WritePushPromise(p PushPromiseParam) error
- func (f *Framer) WriteRSTStream(streamID uint32, code ErrCode) error
- func (f *Framer) WriteRawFrame(t FrameType, flags Flags, streamID uint32, payload []byte) error
- func (f *Framer) WriteSettings(settings ...Setting) error
- func (f *Framer) WriteSettingsAck() error
- func (f *Framer) WriteWindowUpdate(streamID, incr uint32) error
- type GoAwayError
- type GoAwayFrame
- type HPACKConfig
- type HPACKHuffmanMode
- type HPACKNameReferencePolicy
- type HPACKRepresentation
- type Handler
- type Header
- type HeadersFrame
- type HeadersFrameParam
- type MetaHeadersFrame
- type NetHTTPClientConn
- func (cc NetHTTPClientConn) Available() int
- func (cc NetHTTPClientConn) Close() error
- func (cc NetHTTPClientConn) Err() error
- func (cc NetHTTPClientConn) InFlight() int
- func (cc NetHTTPClientConn) Ping(ctx context.Context) error
- func (cc NetHTTPClientConn) Release()
- func (cc NetHTTPClientConn) Reserve() error
- func (cc NetHTTPClientConn) RoundTrip(req *ClientRequest) (*ClientResponse, error)
- type OpenStreamOptions
- type PingFrame
- type PriorityFrame
- type PriorityParam
- type PriorityRequest
- type PriorityUpdateFrame
- type PushOptions
- type PushPromiseFrame
- type PushPromiseParam
- type RSTStreamFrame
- type ReceiveWindowUpdateInfo
- type RequestBodyInfo
- type RequestBodyOptions
- type RequestHeaderField
- type ResponseWriter
- type RoundTripOpt
- type ServeConnOpts
- type Server
- type ServerConfig
- type ServerRequest
- type Setting
- type SettingID
- type SettingsFrame
- func (f *SettingsFrame) ForeachSetting(fn func(Setting) error) error
- func (f *SettingsFrame) HasDuplicates() bool
- func (f *SettingsFrame) IsAck() bool
- func (f *SettingsFrame) NumSettings() int
- func (f *SettingsFrame) Setting(i int) Setting
- func (f *SettingsFrame) Value(id SettingID) (v uint32, ok bool)
- type StreamError
- type Transport
- func (t *Transport) AddConn(scheme, authority string, c net.Conn) error
- func (t *Transport) CloseIdleConnections()
- func (t *Transport) Connections() []*ClientConn
- func (t *Transport) HasConnection(scheme, authority string) bool
- func (t *Transport) IdleConnStrsForTesting() []string
- func (t *Transport) NewClientConn(c net.Conn, internalStateHook func()) (NetHTTPClientConn, error)
- func (t *Transport) RoundTrip(req *ClientRequest) (*ClientResponse, error)
- func (t *Transport) RoundTripOpt(req *ClientRequest, opt RoundTripOpt) (*ClientResponse, error)
- type TransportConfig
- type UnknownFrame
- type WindowUpdateFrame
- type WriteScheduler
Constants ¶
const ( // ClientPreface is the string that must be sent by new // connections from clients. ClientPreface = "PRI * HTTP/2.0\r\n\r\nSM\r\n\r\n" // NextProtoTLS is the NPN/ALPN protocol negotiated during // HTTP/2's TLS setup. NextProtoTLS = "h2" )
const DefaultMaxHeaderBytes = 1 << 20 // keep this in sync with net/http
const TimeFormat = "Mon, 02 Jan 2006 15:04:05 GMT" // keep in sync with net/http
const TrailerPrefix = "Trailer:"
TrailerPrefix is a magic prefix for ResponseWriter.Header map keys that, if present, signals that the map entry is actually for the response trailers, and not the response headers. The prefix is stripped after the ServeHTTP call finishes and the values are sent in the trailers.
This mechanism is intended only for trailers that are not known prior to the headers being written. If the set of trailers is fixed or known before the header is written, the normal Go trailers mechanism is preferred:
https://golang.org/pkg/net/http/#ResponseWriter https://golang.org/pkg/net/http/#example_ResponseWriter_trailers
Variables ¶
var ( NoBody io.ReadCloser LocalAddrContextKey any )
Variables defined in net/http and initialized by an init func in that package.
NoBody and LocalAddrContextKey have concrete types in net/http, and therefore can't be moved into a common package without introducing a dependency cycle.
var ( ErrAbortHandler = internal.ErrAbortHandler ErrBodyNotAllowed = internal.ErrBodyNotAllowed ErrNotSupported = errors.ErrUnsupported ErrSkipAltProtocol = internal.ErrSkipAltProtocol )
var ( NewConnContextKey = new("NewConnContextKey") ConnectionStateContextKey = new("ConnectionStateContextKey") )
var ( ErrRecursivePush = errors.New("http2: recursive push not allowed") ErrPushLimitReached = errors.New("http2: push would exceed peer's SETTINGS_MAX_CONCURRENT_STREAMS") )
Push errors.
var DebugGoroutines = os.Getenv("DEBUG_HTTP2_GOROUTINES") == "1"
var ErrFrameTooLarge = errors.New("http2: frame too large")
ErrFrameTooLarge is returned from Framer.ReadFrame when the peer sends a frame that is larger than declared with SetMaxReadFrameSize.
var ErrNoCachedConn error = noCachedConnError{}
var (
VerboseLogs bool
)
Functions ¶
This section is empty.
Types ¶
type ClientConn ¶
type ClientConn struct {
// contains filtered or unexported fields
}
ClientConn is the state of a single HTTP/2 client connection to an HTTP/2 server.
func (*ClientConn) CanTakeNewRequest ¶
func (cc *ClientConn) CanTakeNewRequest() bool
CanTakeNewRequest reports whether the connection can take a new request, meaning it has not been closed or received or sent a GOAWAY.
If the caller is going to immediately make a new request on this connection, use ReserveNewRequest instead.
func (*ClientConn) Close ¶
func (cc *ClientConn) Close() error
Close closes the client connection immediately.
In-flight requests are interrupted. For a graceful shutdown, use Shutdown instead.
func (*ClientConn) NetworkIdleTime ¶
func (cc *ClientConn) NetworkIdleTime() time.Duration
NetworkIdleTime measures real socket I/O, including partial frames, without replacing the net.Conn used for TLS state or connection ownership.
func (*ClientConn) Ping ¶
func (cc *ClientConn) Ping(ctx context.Context) error
Ping sends a PING frame to the server and waits for the ack.
func (*ClientConn) ReserveNewRequest ¶
func (cc *ClientConn) ReserveNewRequest() bool
ReserveNewRequest is like CanTakeNewRequest but also reserves a concurrent stream in cc. The reservation is decremented on the next call to RoundTrip.
func (*ClientConn) Retire ¶
func (cc *ClientConn) Retire(ctx context.Context, payload *[8]byte, goAway bool)
Retire optionally probes before closing an idle connection. Retirement prevents new reservations immediately, independently of socket scheduling.
func (*ClientConn) RoundTrip ¶
func (cc *ClientConn) RoundTrip(req *ClientRequest) (*ClientResponse, error)
func (*ClientConn) SetDoNotReuse ¶
func (cc *ClientConn) SetDoNotReuse()
SetDoNotReuse marks cc as not reusable for future HTTP requests.
func (*ClientConn) Shutdown ¶
func (cc *ClientConn) Shutdown(ctx context.Context) error
Shutdown gracefully closes the client connection, waiting for running streams to complete.
func (*ClientConn) State ¶
func (cc *ClientConn) State() ClientConnState
State returns a snapshot of cc's state.
type ClientConnState ¶
type ClientConnState struct {
// Closed is whether the connection is closed.
Closed bool
// Closing is whether the connection is in the process of
// closing. It may be closing due to shutdown, being a
// single-use connection, being marked as DoNotReuse, or
// having received a GOAWAY frame.
Closing bool
// StreamsActive is how many streams are active.
StreamsActive int
// StreamsReserved is how many streams have been reserved via
// ClientConn.ReserveNewRequest.
StreamsReserved int
// StreamsPending is how many requests have been sent in excess
// of the peer's advertised MaxConcurrentStreams setting and
// are waiting for other streams to complete.
StreamsPending int
// MaxConcurrentStreams is how many concurrent streams the
// peer advertised as acceptable. Zero means no SETTINGS
// frame has been received yet.
MaxConcurrentStreams uint32
// LastIdle, if non-zero, is when the connection last
// transitioned to idle state.
LastIdle time.Time
}
ClientConnState describes the state of a ClientConn.
type ClientRequest ¶
type ClientRequest struct {
// PrepareHeaders optionally returns private headers and request metadata
// after connection selection. The owning HTTP adapter validates the result.
PrepareHeaders func() (Header, context.Context, error)
Context context.Context
Method string
URL *url.URL
Header Header
Trailer Header
Body io.ReadCloser
Host string
GetBody func() (io.ReadCloser, error)
ContentLength int64
Cancel <-chan struct{}
Close bool
ResTrailer *Header
// contains filtered or unexported fields
}
A ClientRequest is a Request used by the HTTP/2 client (Transport).
func (*ClientRequest) Clone ¶
func (req *ClientRequest) Clone() *ClientRequest
Clone makes a shallow copy of ClientRequest.
Clone is only used in shouldRetryRequest. We can drop it if we ever get rid of or rework that function.
type ClientResponse ¶
type ClientResponse struct {
Status string // e.g. "200"
StatusCode int // e.g. 200
ContentLength int64
Uncompressed bool
Header Header
Trailer Header
Body io.ReadCloser
TLS *tls.ConnectionState
}
A ClientResponse is a Request used by the HTTP/2 client (Transport).
type Config ¶
type Config struct {
Fingerprint *Fingerprint
MaxConcurrentStreams int
StrictMaxConcurrentRequests bool
MaxDecoderHeaderTableSize int
MaxEncoderHeaderTableSize int
MaxReadFrameSize int
MaxReceiveBufferPerConnection int
MaxReceiveBufferPerStream int
SendPingTimeout time.Duration
PingTimeout time.Duration
WriteByteTimeout time.Duration
PermitProhibitedCipherSuites bool
CountError func(errType string)
}
Config must be kept in sync with net/http.HTTP2Config.
type ConnectionCloseInfo ¶
type ConnectionCloseInfo struct {
// Cause is the original terminal error, or nil for local idle/drain closes.
Cause error
// ActiveStreams counts streams still owned when the close begins.
ActiveStreams int
// PeerGoAway reports whether the peer previously sent a GOAWAY frame.
PeerGoAway bool
// ProtocolError reports a connection-level frame parsing error. Its required
// code takes precedence over the options returned by the policy.
ProtocolError bool
// Code is the required code when ProtocolError is true.
Code ErrCode
// Detail is the framer's diagnostic for a protocol error, when available.
Detail string
}
ConnectionCloseInfo describes a terminal connection close. Cause is nil for local idle/drain closes; read-loop closes retain the original socket error.
type ConnectionCloseOptions ¶
type ConnectionCloseOptions struct {
// SendGoAway requests a frame when none has already been sent.
SendGoAway bool
// Code is the final HTTP/2 error code.
Code ErrCode
// LastStreamID identifies the last accepted server-initiated stream.
LastStreamID uint32
// DebugData supplies optional diagnostic bytes. They are copied and bounded
// to fit a minimum-size HTTP/2 frame before the asynchronous write begins.
DebugData []byte
}
ConnectionCloseOptions selects an optional final GOAWAY. Existing protocol error or graceful-shutdown GOAWAY frames take precedence over this option.
type ConnectionError ¶
type ConnectionError ErrCode
ConnectionError is an error that results in the termination of the entire connection.
func (ConnectionError) Error ¶
func (e ConnectionError) Error() string
type ConnectionErrorInfo ¶
type ConnectionErrorInfo struct {
Conn net.Conn // Underlying connection; do not read, write or close it from the policy.
FrameType FrameType // FrameRSTStream or FrameGoAway.
StreamID uint32 // Reset stream ID; zero for GOAWAY.
Code ErrCode // Error code sent by the peer.
}
ConnectionErrorInfo describes a peer error before stream or connection shutdown.
type ContinuationFrame ¶
type ContinuationFrame struct {
FrameHeader
// contains filtered or unexported fields
}
A ContinuationFrame is used to continue a sequence of header block fragments. See https://httpwg.org/specs/rfc7540.html#rfc.section.6.10
func (*ContinuationFrame) HeaderBlockFragment ¶
func (f *ContinuationFrame) HeaderBlockFragment() []byte
func (*ContinuationFrame) HeadersEnded ¶
func (f *ContinuationFrame) HeadersEnded() bool
type DataFrame ¶
type DataFrame struct {
FrameHeader
// contains filtered or unexported fields
}
A DataFrame conveys arbitrary, variable-length sequences of octets associated with a stream. See https://httpwg.org/specs/rfc7540.html#rfc.section.6.1
func (*DataFrame) Data ¶
Data returns the frame's data octets, not including any padding size byte or padding suffix bytes. The caller must not retain the returned memory past the next call to ReadFrame.
func (*DataFrame) StreamEnded ¶
type ErrCode ¶
type ErrCode uint32
An ErrCode is an unsigned 32-bit error code as defined in the HTTP/2 spec.
const ( ErrCodeNo ErrCode = 0x0 ErrCodeProtocol ErrCode = 0x1 ErrCodeInternal ErrCode = 0x2 ErrCodeFlowControl ErrCode = 0x3 ErrCodeSettingsTimeout ErrCode = 0x4 ErrCodeStreamClosed ErrCode = 0x5 ErrCodeFrameSize ErrCode = 0x6 ErrCodeRefusedStream ErrCode = 0x7 ErrCodeCancel ErrCode = 0x8 ErrCodeCompression ErrCode = 0x9 ErrCodeConnect ErrCode = 0xa ErrCodeEnhanceYourCalm ErrCode = 0xb ErrCodeInadequateSecurity ErrCode = 0xc ErrCodeHTTP11Required ErrCode = 0xd )
type Fingerprint ¶
type Fingerprint struct {
// InitialPeerSettings supplies authenticated peer settings before any HTTP/2
// bytes are written. It runs once per connection, must be safe for concurrent
// calls, return promptly and not perform I/O or reenter the transport. Results
// are copied. Nil retains native defaults. These settings do not acknowledge
// or replace the peer's first wire SETTINGS frame.
InitialPeerSettings func(net.Conn) ([]Setting, error)
// HealthCheckPayload replaces random opaque data only for automatic idle
// health checks. Nil preserves native random payloads; explicit Ping calls
// and acknowledgement echoing are unaffected.
HealthCheckPayload *[8]byte
// WriteBufferSize sets the connection writer buffer; zero uses the native
// default. The supported range is 0..1048576 bytes.
WriteBufferSize int
// RequestBodyPolicy selects source-read boundaries and DATA limits for each
// upload. It runs while encoding headers and must return promptly, be safe
// across connections and never reenter the transport. Nil is native behavior.
RequestBodyPolicy func(RequestBodyInfo) RequestBodyOptions
// ConnectionClosePolicy optionally sends a final GOAWAY before closing.
// It runs once outside connection locks, must return promptly and be safe
// across connections. Nil preserves native close behavior.
ConnectionClosePolicy func(ConnectionCloseInfo) ConnectionCloseOptions
// ConnectionErrorPolicy promotes a peer RST_STREAM or GOAWAY to immediate
// connection shutdown when it returns true. Active requests receive the
// peer error; no GOAWAY is sent in reply. Nil retains native handling.
// Called on the read loop without connection locks; it must not block or
// mutate Conn. RST_STREAM for an inactive stream does not invoke it.
ConnectionErrorPolicy func(ConnectionErrorInfo) bool
// StreamReceiveWindow increases client-created streams with an initial
// WINDOW_UPDATE after HEADERS, independently of SETTINGS_INITIAL_WINDOW_SIZE.
StreamReceiveWindow uint32
ReceiveWindowUpdatePolicy func(ReceiveWindowUpdateInfo) bool
Settings []Setting
StreamID uint32
ConnectionFlow uint32
PriorityParam PriorityParam
PriorityFrames []PriorityFrame
HPACK *HPACKConfig
HeaderPriority func(PriorityRequest) PriorityParam
ChainStreamDependencies bool
}
Fingerprint controls the client's HTTP/2 connection and request representation. A nil Fingerprint retains the upstream defaults.
func (*Fingerprint) Clone ¶
func (fp *Fingerprint) Clone() *Fingerprint
Clone freezes mutable configuration when a connection is created.
type Flags ¶
type Flags uint8
Flags is a bitmask of HTTP/2 flags. The meaning of flags varies depending on the frame type.
const ( // Data Frame FlagDataEndStream Flags = 0x1 FlagDataPadded Flags = 0x8 // Headers Frame FlagHeadersEndStream Flags = 0x1 FlagHeadersEndHeaders Flags = 0x4 FlagHeadersPadded Flags = 0x8 FlagHeadersPriority Flags = 0x20 // Settings Frame FlagSettingsAck Flags = 0x1 // Ping Frame FlagPingAck Flags = 0x1 // Continuation Frame FlagContinuationEndHeaders Flags = 0x4 FlagPushPromiseEndHeaders Flags = 0x4 FlagPushPromisePadded Flags = 0x8 )
Frame-specific FrameHeader flag bits.
type Frame ¶
type Frame interface {
Header() FrameHeader
// contains filtered or unexported methods
}
A Frame is the base interface implemented by all frame types. Callers will generally type-assert the specific frame type: *HeadersFrame, *SettingsFrame, *WindowUpdateFrame, etc.
Frames are only valid until the next call to Framer.ReadFrame.
type FrameHeader ¶
type FrameHeader struct {
// Type is the 1 byte frame type. There are ten standard frame
// types, but extension frame types may be written by WriteRawFrame
// and will be returned by ReadFrame (as UnknownFrame).
Type FrameType
// Flags are the 1 byte of 8 potential bit flags per frame.
// They are specific to the frame type.
Flags Flags
// Length is the length of the frame, not including the 9 byte header.
// The maximum size is one byte less than 16MB (uint24), but only
// frames up to 16KB are allowed without peer agreement.
Length uint32
// StreamID is which stream this frame is for. Certain frames
// are not stream-specific, in which case this field is 0.
StreamID uint32
// contains filtered or unexported fields
}
A FrameHeader is the 9 byte header of all HTTP/2 frames.
See https://httpwg.org/specs/rfc7540.html#FrameHeader
func ReadFrameHeader ¶
func ReadFrameHeader(r io.Reader) (FrameHeader, error)
ReadFrameHeader reads 9 bytes from r and returns a FrameHeader. Most users should use Framer.ReadFrame instead.
func (FrameHeader) Header ¶
func (h FrameHeader) Header() FrameHeader
Header returns h. It exists so FrameHeaders can be embedded in other specific frame types and implement the Frame interface.
func (FrameHeader) String ¶
func (h FrameHeader) String() string
type FrameType ¶
type FrameType uint8
A FrameType is a registered frame type as defined in https://httpwg.org/specs/rfc7540.html#rfc.section.11.2 and other future RFCs.
const ( FrameData FrameType = 0x0 FrameHeaders FrameType = 0x1 FramePriority FrameType = 0x2 FrameRSTStream FrameType = 0x3 FrameSettings FrameType = 0x4 FramePushPromise FrameType = 0x5 FramePing FrameType = 0x6 FrameGoAway FrameType = 0x7 FrameWindowUpdate FrameType = 0x8 FrameContinuation FrameType = 0x9 FramePriorityUpdate FrameType = 0x10 )
type FrameWriteRequest ¶
type FrameWriteRequest struct {
// contains filtered or unexported fields
}
FrameWriteRequest is a request to write a frame.
func (FrameWriteRequest) Consume ¶
func (wr FrameWriteRequest) Consume(n int32) (FrameWriteRequest, FrameWriteRequest, int)
Consume consumes min(n, available) bytes from this frame, where available is the number of flow control bytes available on the stream. Consume returns 0, 1, or 2 frames, where the integer return value gives the number of frames returned.
If flow control prevents consuming any bytes, this returns (_, _, 0). If the entire frame was consumed, this returns (wr, _, 1). Otherwise, this returns (consumed, rest, 2), where 'consumed' contains the consumed bytes and 'rest' contains the remaining bytes. The consumed bytes are deducted from the underlying stream's flow control budget.
func (FrameWriteRequest) DataSize ¶
func (wr FrameWriteRequest) DataSize() int
DataSize returns the number of flow control bytes that must be consumed to write this entire frame. This is 0 for non-DATA frames.
func (FrameWriteRequest) StreamID ¶
func (wr FrameWriteRequest) StreamID() uint32
StreamID returns the id of the stream this frame will be written to. 0 is used for non-stream frames such as PING and SETTINGS.
func (FrameWriteRequest) String ¶
func (wr FrameWriteRequest) String() string
String is for debugging only.
type Framer ¶
type Framer struct {
// AllowIllegalWrites permits the Framer's Write methods to
// write frames that do not conform to the HTTP/2 spec. This
// permits using the Framer to test other HTTP/2
// implementations' conformance to the spec.
// If false, the Write methods will prefer to return an error
// rather than comply.
AllowIllegalWrites bool
// AllowIllegalReads permits the Framer's ReadFrame method
// to return non-compliant frames or frame orders.
// This is for testing and permits using the Framer to test
// other HTTP/2 implementations' conformance to the spec.
// It is not compatible with ReadMetaHeaders.
AllowIllegalReads bool
// ReadMetaHeaders if non-nil causes ReadFrame to merge
// HEADERS and CONTINUATION frames together and return
// MetaHeadersFrame instead.
ReadMetaHeaders *hpack.Decoder
// MaxHeaderListSize is the http2 MAX_HEADER_LIST_SIZE.
// It's used only if ReadMetaHeaders is set; 0 means a sane default
// (currently 16MB)
// If the limit is hit, MetaHeadersFrame.Truncated is set true.
MaxHeaderListSize uint32
// MaxHeaderValueCount is the maximum permitted number of
// header values.
// It's used only if ReadMetaHeaders is set; 0 means no limit.
// If the limit is hit, MetaHeadersFrame.Truncated is set true.
MaxHeaderValueCount int
// contains filtered or unexported fields
}
A Framer reads and writes Frames.
func (*Framer) ErrorDetail ¶
ErrorDetail returns a more detailed error of the last error returned by Framer.ReadFrame. For instance, if ReadFrame returns a StreamError with code PROTOCOL_ERROR, ErrorDetail will say exactly what was invalid. ErrorDetail is not guaranteed to return a non-nil value and like the rest of the http2 package, its return value is not protected by an API compatibility promise. ErrorDetail is reset after the next call to ReadFrame.
func (*Framer) ReadFrame ¶
ReadFrame reads a single frame. The returned Frame is only valid until the next call to ReadFrame or ReadFrameBodyForHeader.
If the frame is larger than previously set with SetMaxReadFrameSize, the returned error is ErrFrameTooLarge. Other errors may be of type ConnectionError, StreamError, or anything else from the underlying reader.
If ReadFrame returns an error and a non-nil Frame, the Frame's StreamID indicates the stream responsible for the error.
func (*Framer) ReadFrameForHeader ¶
func (fr *Framer) ReadFrameForHeader(fh FrameHeader) (Frame, error)
ReadFrameForHeader reads the payload for the frame with the given FrameHeader.
It behaves identically to ReadFrame, other than not checking the maximum frame size.
func (*Framer) ReadFrameHeader ¶
func (fr *Framer) ReadFrameHeader() (FrameHeader, error)
ReadFrameHeader reads the header of the next frame. It reads the 9-byte fixed frame header, and does not read any portion of the frame payload. The caller is responsible for consuming the payload, either with ReadFrameForHeader or directly from the Framer's io.Reader.
If the frame is larger than previously set with SetMaxReadFrameSize, it returns the frame header and ErrFrameTooLarge.
If the returned FrameHeader.StreamID is non-zero, it indicates the stream responsible for the error.
func (*Framer) SetMaxReadFrameSize ¶
SetMaxReadFrameSize sets the maximum size of a frame that will be read by a subsequent call to ReadFrame. It is the caller's responsibility to advertise this limit with a SETTINGS frame.
func (*Framer) SetReuseFrames ¶
func (fr *Framer) SetReuseFrames()
SetReuseFrames allows the Framer to reuse Frames. If called on a Framer, Frames returned by calls to ReadFrame are only valid until the next call to ReadFrame.
func (*Framer) WriteContinuation ¶
func (f *Framer) WriteContinuation(streamID uint32, endHeaders bool, headerBlockFragment []byte) error
WriteContinuation writes a CONTINUATION frame.
It will perform exactly one Write to the underlying Writer. It is the caller's responsibility to not call other Write methods concurrently.
func (*Framer) WriteData ¶
WriteData writes a DATA frame.
It will perform exactly one Write to the underlying Writer. It is the caller's responsibility not to violate the maximum frame size and to not call other Write methods concurrently.
func (*Framer) WriteDataPadded ¶
WriteDataPadded writes a DATA frame with optional padding.
If pad is nil, the padding bit is not sent. The length of pad must not exceed 255 bytes. The bytes of pad must all be zero, unless f.AllowIllegalWrites is set.
It will perform exactly one Write to the underlying Writer. It is the caller's responsibility not to violate the maximum frame size and to not call other Write methods concurrently.
func (*Framer) WriteGoAway ¶
func (*Framer) WriteHeaders ¶
func (f *Framer) WriteHeaders(p HeadersFrameParam) error
WriteHeaders writes a single HEADERS frame.
This is a low-level header writing method. Encoding headers and splitting them into any necessary CONTINUATION frames is handled elsewhere.
It will perform exactly one Write to the underlying Writer. It is the caller's responsibility to not call other Write methods concurrently.
func (*Framer) WritePriority ¶
func (f *Framer) WritePriority(streamID uint32, p PriorityParam) error
WritePriority writes a PRIORITY frame.
It will perform exactly one Write to the underlying Writer. It is the caller's responsibility to not call other Write methods concurrently.
func (*Framer) WritePriorityUpdate ¶
WritePriorityUpdate writes a PRIORITY_UPDATE frame.
It will perform exactly one Write to the underlying Writer. It is the caller's responsibility to not call other Write methods concurrently.
func (*Framer) WritePushPromise ¶
func (f *Framer) WritePushPromise(p PushPromiseParam) error
WritePushPromise writes a single PushPromise Frame.
As with Header Frames, This is the low level call for writing individual frames. Continuation frames are handled elsewhere.
It will perform exactly one Write to the underlying Writer. It is the caller's responsibility to not call other Write methods concurrently.
func (*Framer) WriteRSTStream ¶
WriteRSTStream writes a RST_STREAM frame.
It will perform exactly one Write to the underlying Writer. It is the caller's responsibility to not call other Write methods concurrently.
func (*Framer) WriteRawFrame ¶
WriteRawFrame writes a raw frame. This can be used to write extension frames unknown to this package.
func (*Framer) WriteSettings ¶
WriteSettings writes a SETTINGS frame with zero or more settings specified and the ACK bit not set.
It will perform exactly one Write to the underlying Writer. It is the caller's responsibility to not call other Write methods concurrently.
func (*Framer) WriteSettingsAck ¶
WriteSettingsAck writes an empty SETTINGS frame with the ACK bit set.
It will perform exactly one Write to the underlying Writer. It is the caller's responsibility to not call other Write methods concurrently.
func (*Framer) WriteWindowUpdate ¶
WriteWindowUpdate writes a WINDOW_UPDATE frame. The increment value must be between 1 and 2,147,483,647, inclusive. If the Stream ID is zero, the window update applies to the connection as a whole.
type GoAwayError ¶
GoAwayError is returned by the Transport when the server closes the TCP connection after sending a GOAWAY frame.
func (GoAwayError) Error ¶
func (e GoAwayError) Error() string
type GoAwayFrame ¶
type GoAwayFrame struct {
FrameHeader
LastStreamID uint32
ErrCode ErrCode
// contains filtered or unexported fields
}
A GoAwayFrame informs the remote peer to stop creating streams on this connection. See https://httpwg.org/specs/rfc7540.html#rfc.section.6.8
func (*GoAwayFrame) DebugData ¶
func (f *GoAwayFrame) DebugData() []byte
DebugData returns any debug data in the GOAWAY frame. Its contents are not defined. The caller must not retain the returned memory past the next call to ReadFrame.
type HPACKConfig ¶
type HPACKConfig struct {
// DeduplicateTableSizeUpdates ignores SETTINGS that repeat the current
// encoder capacity, preserving any already pending minimum/maximum updates.
DeduplicateTableSizeUpdates bool
Huffman HPACKHuffmanMode
NameReferencePolicy HPACKNameReferencePolicy
Default HPACKRepresentation
Representations map[string]HPACKRepresentation
Policy func(name, value string) HPACKRepresentation
// IndexingLimit bounds NEW dynamic entries by their HPACK size, including
// the 32-byte overhead. Existing exact entries can still be referenced.
// Nil retains the upstream capacity bound. Zero returned by the callback
// disables new entries. Called under the header lock; must not reenter.
IndexingLimit func(tableCapacity uint32) uint32
}
HPACKConfig controls request and trailer encoding without replacing x/net's encoder, dynamic table, size updates or Huffman implementation. Callbacks must not reenter the transport. Representations override Policy, then Default.
func (*HPACKConfig) Clone ¶
func (c *HPACKConfig) Clone() *HPACKConfig
func (*HPACKConfig) Validate ¶
func (c *HPACKConfig) Validate() error
type HPACKHuffmanMode ¶
type HPACKHuffmanMode uint8
HPACKHuffmanMode selects automatic, always or disabled Huffman literal strings.
const ( HPACKHuffmanDefault HPACKHuffmanMode = iota HPACKHuffmanAlways HPACKHuffmanNever )
type HPACKNameReferencePolicy ¶
type HPACKNameReferencePolicy uint8
HPACKNameReferencePolicy selects the name entry used by literal fields.
const ( HPACKNameReferenceDefault HPACKNameReferencePolicy = iota // HPACKNameReferenceLast scans static entries, then dynamic entries from // newest to oldest. An exact match wins; otherwise the last matching name wins. HPACKNameReferenceLast // HPACKNameReferenceFirst uses the first matching static name; otherwise // it keeps the upstream encoder's most recent dynamic name reference. HPACKNameReferenceFirst )
type HPACKRepresentation ¶
type HPACKRepresentation uint8
HPACKRepresentation selects a field's representation. Default allows the upstream encoder to reuse an exact table entry or insert a new entry that fits.
const ( HPACKDefault HPACKRepresentation = iota // HPACKWithoutIndexing always emits a literal without inserting it. HPACKWithoutIndexing // HPACKNeverIndex always emits a literal with the never-index instruction. HPACKNeverIndex // HPACKIncrementalIndexing reuses exact matches, otherwise emits an // incremental literal even when the entry exceeds the table capacity. // An oversized insertion empties the table, as required by RFC 7541 4.4. HPACKIncrementalIndexing )
type Handler ¶
type Handler interface {
ServeHTTP(*ResponseWriter, *ServerRequest)
}
type Header ¶
type Header = textproto.MIMEHeader
type HeadersFrame ¶
type HeadersFrame struct {
FrameHeader
// Priority is set if FlagHeadersPriority is set in the FrameHeader.
Priority PriorityParam
// contains filtered or unexported fields
}
A HeadersFrame is used to open a stream and additionally carries a header block fragment.
func (*HeadersFrame) HasPriority ¶
func (f *HeadersFrame) HasPriority() bool
func (*HeadersFrame) HeaderBlockFragment ¶
func (f *HeadersFrame) HeaderBlockFragment() []byte
func (*HeadersFrame) HeadersEnded ¶
func (f *HeadersFrame) HeadersEnded() bool
func (*HeadersFrame) StreamEnded ¶
func (f *HeadersFrame) StreamEnded() bool
type HeadersFrameParam ¶
type HeadersFrameParam struct {
// StreamID is the required Stream ID to initiate.
StreamID uint32
// BlockFragment is part (or all) of a Header Block.
BlockFragment []byte
// EndStream indicates that the header block is the last that
// the endpoint will send for the identified stream. Setting
// this flag causes the stream to enter one of "half closed"
// states.
EndStream bool
// EndHeaders indicates that this frame contains an entire
// header block and is not followed by any
// CONTINUATION frames.
EndHeaders bool
// PadLength is the optional number of bytes of zeros to add
// to this frame.
PadLength uint8
// Priority, if non-zero, includes stream priority information
// in the HEADER frame.
Priority PriorityParam
}
HeadersFrameParam are the parameters for writing a HEADERS frame.
type MetaHeadersFrame ¶
type MetaHeadersFrame struct {
*HeadersFrame
// Fields are the fields contained in the HEADERS and
// CONTINUATION frames. The underlying slice is owned by the
// Framer and must not be retained after the next call to
// ReadFrame.
//
// Fields are guaranteed to be in the correct http2 order and
// not have unknown pseudo header fields or invalid header
// field names or values. Required pseudo header fields may be
// missing, however. Use the MetaHeadersFrame.Pseudo accessor
// method access pseudo headers.
Fields []hpack.HeaderField
// Truncated is whether the max header list size limit was hit
// and Fields is incomplete. The hpack decoder state is still
// valid, however.
Truncated bool
}
A MetaHeadersFrame is the representation of one HEADERS frame and zero or more contiguous CONTINUATION frames and the decoding of their HPACK-encoded contents.
This type of frame does not appear on the wire and is only returned by the Framer when Framer.ReadMetaHeaders is set.
func (*MetaHeadersFrame) PseudoFields ¶
func (mh *MetaHeadersFrame) PseudoFields() []hpack.HeaderField
PseudoFields returns the pseudo header fields of mh. The caller does not own the returned slice.
func (*MetaHeadersFrame) PseudoValue ¶
func (mh *MetaHeadersFrame) PseudoValue(pseudo string) string
PseudoValue returns the given pseudo header field's value. The provided pseudo field should not contain the leading colon.
func (*MetaHeadersFrame) RegularFields ¶
func (mh *MetaHeadersFrame) RegularFields() []hpack.HeaderField
RegularFields returns the regular (non-pseudo) header fields of mh. The caller does not own the returned slice.
type NetHTTPClientConn ¶
type NetHTTPClientConn struct {
// contains filtered or unexported fields
}
netHTTPClientConn wraps ClientConn and implements the interface net/http expects from the RoundTripper returned by NewClientConn.
func (NetHTTPClientConn) Available ¶
func (cc NetHTTPClientConn) Available() int
func (NetHTTPClientConn) Close ¶
func (cc NetHTTPClientConn) Close() error
func (NetHTTPClientConn) Err ¶
func (cc NetHTTPClientConn) Err() error
func (NetHTTPClientConn) InFlight ¶
func (cc NetHTTPClientConn) InFlight() int
func (NetHTTPClientConn) Release ¶
func (cc NetHTTPClientConn) Release()
func (NetHTTPClientConn) Reserve ¶
func (cc NetHTTPClientConn) Reserve() error
func (NetHTTPClientConn) RoundTrip ¶
func (cc NetHTTPClientConn) RoundTrip(req *ClientRequest) (*ClientResponse, error)
type OpenStreamOptions ¶
type OpenStreamOptions struct {
// PusherID is zero if the stream was initiated by the client. Otherwise,
// PusherID names the stream that pushed the newly opened stream.
PusherID uint32
// contains filtered or unexported fields
}
OpenStreamOptions specifies extra options for WriteScheduler.OpenStream.
type PingFrame ¶
type PingFrame struct {
FrameHeader
Data [8]byte
}
A PingFrame is a mechanism for measuring a minimal round trip time from the sender, as well as determining whether an idle connection is still functional. See https://httpwg.org/specs/rfc7540.html#rfc.section.6.7
type PriorityFrame ¶
type PriorityFrame struct {
FrameHeader
PriorityParam
}
A PriorityFrame specifies the sender-advised priority of a stream. See https://httpwg.org/specs/rfc7540.html#rfc.section.6.3
type PriorityParam ¶
type PriorityParam struct {
// StreamDep is a 31-bit stream identifier for the
// stream that this stream depends on. Zero means no
// dependency.
StreamDep uint32
// Exclusive is whether the dependency is exclusive.
Exclusive bool
// Weight is the stream's zero-indexed weight. It should be
// set together with StreamDep, or neither should be set. Per
// the spec, "Add one to the value to obtain a weight between
// 1 and 256."
Weight uint8
// contains filtered or unexported fields
}
PriorityParam are the stream prioritization parameters.
func (PriorityParam) IsZero ¶
func (p PriorityParam) IsZero() bool
type PriorityRequest ¶
type PriorityRequest struct {
Context context.Context
Method string
URL *url.URL
Header map[string][]string
}
PriorityRequest is a read-only view of the request being assigned a stream. The callback runs under the connection's header write lock; it must not reenter the transport or mutate Header or URL. Different connections may call it concurrently.
type PriorityUpdateFrame ¶
type PriorityUpdateFrame struct {
FrameHeader
Priority string
PrioritizedStreamID uint32
}
PriorityUpdateFrame is a PRIORITY_UPDATE frame as described in https://www.rfc-editor.org/rfc/rfc9218.html#name-the-priority_update-frame.
type PushOptions ¶
type PushPromiseFrame ¶
type PushPromiseFrame struct {
FrameHeader
PromiseID uint32
// contains filtered or unexported fields
}
A PushPromiseFrame is used to initiate a server stream. See https://httpwg.org/specs/rfc7540.html#rfc.section.6.6
func (*PushPromiseFrame) HeaderBlockFragment ¶
func (f *PushPromiseFrame) HeaderBlockFragment() []byte
func (*PushPromiseFrame) HeadersEnded ¶
func (f *PushPromiseFrame) HeadersEnded() bool
type PushPromiseParam ¶
type PushPromiseParam struct {
// StreamID is the required Stream ID to initiate.
StreamID uint32
// PromiseID is the required Stream ID which this
// Push Promises
PromiseID uint32
// BlockFragment is part (or all) of a Header Block.
BlockFragment []byte
// EndHeaders indicates that this frame contains an entire
// header block and is not followed by any
// CONTINUATION frames.
EndHeaders bool
// PadLength is the optional number of bytes of zeros to add
// to this frame.
PadLength uint8
}
PushPromiseParam are the parameters for writing a PUSH_PROMISE frame.
type RSTStreamFrame ¶
type RSTStreamFrame struct {
FrameHeader
ErrCode ErrCode
}
A RSTStreamFrame allows for abnormal termination of a stream. See https://httpwg.org/specs/rfc7540.html#rfc.section.6.4
type ReceiveWindowUpdateInfo ¶
type ReceiveWindowUpdateInfo struct {
// Window is the initial connection or stream receive window.
Window int32
// Available is credit still available to the peer. Zero does not imply an
// empty application read buffer: accepted DATA may remain unread.
Available int32
// Pending is consumed credit not yet returned in a WINDOW_UPDATE.
Pending int32
// Elapsed is time since policy initialization or the last emitted update.
Elapsed time.Duration
}
ReceiveWindowUpdateInfo describes receive credit when the application returns consumed bytes. The policy runs under the connection lock, must return promptly and must be concurrency safe. It must not call back into the transport. Returning false defers the update even when peer credit is exhausted. A custom policy owns progress and must eventually release pending credit; nil retains the native batching and exhausted-credit behavior.
type RequestBodyInfo ¶
type RequestBodyInfo struct {
Fields []RequestHeaderField // Effective ordered wire fields.
ContentLength int64 // Declared length, or -1 when unknown.
}
RequestBodyInfo describes an upload without reading its body. Fields belong to this call and may be inspected by the policy.
type RequestBodyOptions ¶
type RequestBodyOptions struct {
MaxDataFrameSize int // Additional cap, still bounded by peer credit and frame size.
MaxReadSize int // Cap for each fresh source read; short reads do not consume the next read's budget.
ReadBufferSize int // Buffered source boundary and maximum read size.
ReadCycleSize int // Repeating source-read budget, independent of its buffer.
InitialReadSize int // First source-read budget; zero uses ReadCycleSize.
ResetCycleOnFlowBlock bool // Restart the cycle after waiting for peer receive credit.
HeaderBytes int64 // Virtual prefix consumed before the body's first read.
}
RequestBodyOptions controls upload reads and DATA framing. Zero fields retain native behavior. Sizes must be nonnegative and at most 1 MiB. ReadCycleSize and InitialReadSize require ReadBufferSize. HeaderBytes accounts for a virtual serialized prefix in a buffered source; it never reads or changes the body. Short reads remain short: the transport does not wait to fill these sizes.
type RequestHeaderField ¶
type RequestHeaderField struct {
Name string // Lowercase wire name.
Value string // Value after transport defaults and normalization.
}
RequestHeaderField is an effective, ordered request field, including pseudo-fields.
type ResponseWriter ¶
type ResponseWriter = responseWriter
type RoundTripOpt ¶
type RoundTripOpt struct {
// OnlyCachedConn controls whether RoundTripOpt may
// create a new TCP connection. If set true and
// no cached connection is available, RoundTripOpt
// will return ErrNoCachedConn.
OnlyCachedConn bool
}
RoundTripOpt are options for the Transport.RoundTripOpt method.
type ServeConnOpts ¶
type ServeConnOpts struct {
// Context is the base context to use.
// If nil, context.Background is used.
Context context.Context
// BaseConfig optionally sets the base configuration
// for values. If nil, defaults are used.
BaseConfig ServerConfig
// Handler specifies which handler to use for processing
// requests. If nil, BaseConfig.Handler is used. If BaseConfig
// or BaseConfig.Handler is nil, http.DefaultServeMux is used.
Handler Handler
// Settings is the decoded contents of the HTTP2-Settings header
// in an h2c upgrade request.
Settings []byte
UpgradeRequest *ServerRequest
// SawClientPreface is set if the HTTP/2 connection preface
// has already been read from the connection.
SawClientPreface bool
}
ServeConnOpts are options for the Server.ServeConn method.
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server is an HTTP/2 server.
func (*Server) GracefulShutdown ¶
func (s *Server) GracefulShutdown()
func (*Server) ServeConn ¶
func (s *Server) ServeConn(c net.Conn, opts *ServeConnOpts)
ServeConn serves HTTP/2 requests on the provided connection and blocks until the connection is no longer readable.
ServeConn starts speaking HTTP/2 assuming that c has not had any reads or writes. It writes its initial settings frame and expects to be able to read the preface and settings frame from the client. If c has a ConnectionState method like a *tls.Conn, the ConnectionState is used to verify the TLS ciphersuite and to set the Request.TLS field in Handlers.
ServeConn does not support h2c by itself. Any h2c support must be implemented in terms of providing a suitably-behaving net.Conn.
The opts parameter is optional. If nil, default values are used.
type ServerConfig ¶
type ServerConfig interface {
MaxHeaderBytes() int
MaxHeaderValueCount() int
ConnState(net.Conn, ConnState)
DoKeepAlives() bool
WriteTimeout() time.Duration
SendPingTimeout() time.Duration
ErrorLog() *log.Logger
ReadTimeout() time.Duration
HTTP2Config() Config
DisableClientPriority() bool
IdleTimeout() time.Duration
}
ServerConfig is configuration from an http.Server.
type ServerRequest ¶
type ServerRequest struct {
Context context.Context
Proto string // e.g. "HTTP/1.0"
ProtoMajor int // e.g. 1
ProtoMinor int // e.g. 0
Method string
URL *url.URL
Header Header
Trailer Header
Body io.ReadCloser
Host string
ContentLength int64
RemoteAddr string
RequestURI string
TLS *tls.ConnectionState
MultipartForm *multipart.Form
}
A ServerRequest is a Request used by the HTTP/2 server.
type Setting ¶
type Setting struct {
// ID is which setting is being set.
// See https://httpwg.org/specs/rfc7540.html#SettingFormat
ID SettingID
// Val is the value.
Val uint32
}
Setting is a setting parameter: which setting it is, and its value.
type SettingID ¶
type SettingID uint16
A SettingID is an HTTP/2 setting as defined in https://httpwg.org/specs/rfc7540.html#iana-settings
const ( SettingHeaderTableSize SettingID = 0x1 SettingEnablePush SettingID = 0x2 SettingMaxConcurrentStreams SettingID = 0x3 SettingInitialWindowSize SettingID = 0x4 SettingMaxFrameSize SettingID = 0x5 SettingMaxHeaderListSize SettingID = 0x6 SettingEnableConnectProtocol SettingID = 0x8 SettingNoRFC7540Priorities SettingID = 0x9 )
type SettingsFrame ¶
type SettingsFrame struct {
FrameHeader
// contains filtered or unexported fields
}
A SettingsFrame conveys configuration parameters that affect how endpoints communicate, such as preferences and constraints on peer behavior.
See https://httpwg.org/specs/rfc7540.html#SETTINGS
func (*SettingsFrame) ForeachSetting ¶
func (f *SettingsFrame) ForeachSetting(fn func(Setting) error) error
ForeachSetting runs fn for each setting. It stops and returns the first error.
func (*SettingsFrame) HasDuplicates ¶
func (f *SettingsFrame) HasDuplicates() bool
HasDuplicates reports whether f contains any duplicate setting IDs.
func (*SettingsFrame) IsAck ¶
func (f *SettingsFrame) IsAck() bool
func (*SettingsFrame) NumSettings ¶
func (f *SettingsFrame) NumSettings() int
func (*SettingsFrame) Setting ¶
func (f *SettingsFrame) Setting(i int) Setting
Setting returns the setting from the frame at the given 0-based index. The index must be >= 0 and less than f.NumSettings().
type StreamError ¶
StreamError is an error that only affects one stream within an HTTP/2 connection.
func (StreamError) As ¶
func (e StreamError) As(target any) bool
This As function permits converting a StreamError into a x/net/http2.StreamError.
func (StreamError) Error ¶
func (e StreamError) Error() string
type Transport ¶
type Transport struct {
// contains filtered or unexported fields
}
Transport is an HTTP/2 Transport.
A Transport internally caches connections to servers. It is safe for concurrent use by multiple goroutines.
func NewTransport ¶
func NewTransport(t1 TransportConfig) *Transport
func (*Transport) CloseIdleConnections ¶
func (t *Transport) CloseIdleConnections()
CloseIdleConnections closes any connections which were previously connected from previous requests but are now sitting idle. It does not interrupt any connections currently in use.
func (*Transport) Connections ¶
func (t *Transport) Connections() []*ClientConn
Connections snapshots each pooled connection once. Callers may perform maintenance after the pool lock has been released.
func (*Transport) HasConnection ¶
HasConnection observes a reusable pooled session without reserving a stream. Concurrency limits do not hide a live session; normal request admission remains responsible for its queue/dial decision. No connection or stream is created.
func (*Transport) IdleConnStrsForTesting ¶
func (*Transport) NewClientConn ¶
func (t *Transport) NewClientConn(c net.Conn, internalStateHook func()) (NetHTTPClientConn, error)
func (*Transport) RoundTrip ¶
func (t *Transport) RoundTrip(req *ClientRequest) (*ClientResponse, error)
func (*Transport) RoundTripOpt ¶
func (t *Transport) RoundTripOpt(req *ClientRequest, opt RoundTripOpt) (*ClientResponse, error)
RoundTripOpt is like RoundTrip, but takes options.
type TransportConfig ¶
type TransportConfig interface {
MaxHeaderListSize() int64
MaxResponseHeaderBytes() int64
DisableCompression() bool
DisableKeepAlives() bool
ExpectContinueTimeout() time.Duration
ResponseHeaderTimeout() time.Duration
IdleConnTimeout() time.Duration
HTTP2Config() Config
}
TransportConfig is configuration from an http.Transport.
type UnknownFrame ¶
type UnknownFrame struct {
FrameHeader
// contains filtered or unexported fields
}
An UnknownFrame is the frame type returned when the frame type is unknown or no specific frame type parser exists.
func (*UnknownFrame) Payload ¶
func (f *UnknownFrame) Payload() []byte
Payload returns the frame's payload (after the header). It is not valid to call this method after a subsequent call to Framer.ReadFrame, nor is it valid to retain the returned slice. The memory is owned by the Framer and is invalidated when the next frame is read.
type WindowUpdateFrame ¶
type WindowUpdateFrame struct {
FrameHeader
Increment uint32 // never read with high bit set
}
A WindowUpdateFrame is used to implement flow control. See https://httpwg.org/specs/rfc7540.html#rfc.section.6.9
type WriteScheduler ¶
type WriteScheduler interface {
// OpenStream opens a new stream in the write scheduler.
// It is illegal to call this with streamID=0 or with a streamID that is
// already open -- the call may panic.
OpenStream(streamID uint32, options OpenStreamOptions)
// CloseStream closes a stream in the write scheduler. Any frames queued on
// this stream should be discarded. It is illegal to call this on a stream
// that is not open -- the call may panic.
CloseStream(streamID uint32)
// AdjustStream adjusts the priority of the given stream. This may be called
// on a stream that has not yet been opened or has been closed. Note that
// RFC 7540 allows PRIORITY frames to be sent on streams in any state. See:
// https://tools.ietf.org/html/rfc7540#section-5.1
AdjustStream(streamID uint32, priority PriorityParam)
// Push queues a frame in the scheduler. In most cases, this will not be
// called with wr.StreamID()!=0 unless that stream is currently open. The one
// exception is RST_STREAM frames, which may be sent on idle or closed streams.
Push(wr FrameWriteRequest)
// Pop dequeues the next frame to write. Returns false if no frames can
// be written. Frames with a given wr.StreamID() are Pop'd in the same
// order they are Push'd, except RST_STREAM frames. No frames should be
// discarded except by CloseStream.
Pop() (wr FrameWriteRequest, ok bool)
}
WriteScheduler is the interface implemented by HTTP/2 write schedulers. Methods are never called concurrently.
Source Files
¶
- api.go
- ascii.go
- ciphers.go
- client_conn_pool.go
- config.go
- connection_activity.go
- connection_close_policy.go
- connection_error_policy.go
- connection_ping.go
- connection_pool.go
- databuffer.go
- errors.go
- fingerprint.go
- flow.go
- frame.go
- gotrack.go
- header_policy.go
- hpack_literal.go
- http2.go
- indexed_fields.go
- peer_settings.go
- pipe.go
- receive_window.go
- request_body_policy.go
- server.go
- transport.go
- write.go
- writesched.go
- writesched_priority_rfc9218.go
- writesched_roundrobin.go