Documentation ¶
Index ¶
- Constants
- Variables
- func CanonicalHTTP2HeaderKey(s string) string
- type Config
- type Conn
- func (c *Conn) Close() error
- func (c *Conn) CloseTimeout(timeout time.Duration) error
- func (c *Conn) Closed() bool
- func (c *Conn) Flush() error
- func (c *Conn) GoAwayReceived() (bool, *GoAwayFrame)
- func (c *Conn) GoAwaySent() (bool, *GoAwayFrame)
- func (c *Conn) Handshake() error
- func (c *Conn) InitialRecvWindow(streamID uint32) uint32
- func (c *Conn) InitialSendWindow(uint32) uint32
- func (c *Conn) LastStreamID() uint32
- func (c *Conn) LocalAddr() net.Addr
- func (c *Conn) NextStreamID() (uint32, error)
- func (c *Conn) NumActiveStreams() uint32
- func (c *Conn) ReadFrame() (Frame, error)
- func (c *Conn) RecvWindow(streamID uint32) uint32
- func (c *Conn) RemoteAddr() net.Addr
- func (c *Conn) RemoteSettings() Settings
- func (c *Conn) SendWindow(streamID uint32) uint32
- func (c *Conn) ServerConn() bool
- func (c *Conn) Settings() Settings
- func (c *Conn) WriteFrame(frame Frame) error
- type ConnError
- type DataFrame
- type Dialer
- type ErrCode
- type Flags
- type Frame
- type FrameType
- type GoAwayFrame
- type Handler
- type HandshakeError
- type Header
- func (h Header) Add(key, value string)
- func (h Header) Authority() string
- func (h Header) Del(key string)
- func (h Header) Get(key string) string
- func (h Header) Len() (n int)
- func (h Header) Method() string
- func (h Header) Path() string
- func (h Header) Scheme() string
- func (h Header) Set(key, value string)
- func (h Header) SetAuthority(value string)
- func (h Header) SetMethod(value string)
- func (h Header) SetPath(value string)
- func (h Header) SetScheme(value string)
- func (h Header) SetStatus(value string)
- func (h Header) Status() string
- type HeadersFrame
- type MalformedError
- type PingFrame
- type Priority
- type PriorityFrame
- type PushPromiseFrame
- type RSTStreamFrame
- type Server
- type SettingID
- type Settings
- func (s Settings) HeaderTableSize() uint32
- func (s Settings) InitialWindowSize() uint32
- func (s Settings) MaxConcurrentStreams() uint32
- func (s Settings) MaxFrameSize() uint32
- func (s Settings) MaxHeaderListSize() uint32
- func (s Settings) PushEnabled() bool
- func (s *Settings) SetHeaderTableSize(value uint32) error
- func (s *Settings) SetInitialWindowSize(value uint32) error
- func (s *Settings) SetMaxConcurrentStreams(value uint32) error
- func (s *Settings) SetMaxFrameSize(value uint32) error
- func (s *Settings) SetMaxHeaderListSize(value uint32) error
- func (s *Settings) SetPushEnabled(enabled bool) error
- func (s *Settings) SetValue(id SettingID, value uint32) error
- func (s Settings) String() string
- func (s Settings) Value(id SettingID) uint32
- type SettingsFrame
- type StreamError
- type StreamErrorList
- type StreamState
- type UnknownFrame
- type WindowUpdateFrame
Constants ¶
const ( ProtocolTLS = "h2" ProtocolTCP = "h2c" )
HTTP/2 Version Identification, defined in RFC 7540 section 3.1.
const ClientPreface = "PRI * HTTP/2.0\r\n\r\nSM\r\n\r\n"
ClientPreface represents client-side HTTP/2 connection preface, defined in RFC 7540 section 3.5.
Variables ¶
var ErrClosed = errors.New("http2: connection has been closed")
ErrClosed represents connection already closed error.
Functions ¶
func CanonicalHTTP2HeaderKey ¶
CanonicalHTTP2HeaderKey returns the canonical format of the header key s.
Types ¶
type Config ¶
type Config struct { // InitialSettings specifies the Http2Settings to use for the initial // connection settings exchange. If nil, empty settings is used. InitialSettings Settings // HandshakeTimeout specifies the duration for the handshake to complete. HandshakeTimeout time.Duration // AllowLowTLSVersion controls whether a server allows the client's // TLSVersion is lower than TLS 1.2. AllowLowTLSVersion bool // ReadBufSize and WriteBufSize specify I/O buffer sizes. If the buffer // size is zero, then a default value of 4096 is used. The I/O buffer sizes // do not limit the size of the frames that can be sent or received. ReadBufSize, WriteBufSize int }
A Config structure is used to configure a HTTP/2 client or server connection.
type Conn ¶
type Conn struct {
// contains filtered or unexported fields
}
A Conn represents a HTTP/2 connection.
func ClientConn ¶
ClientConn returns a new HTTP/2 client side connection using rawConn as the underlying transport. If config is nil, the default configuration is used. The req parameter optionally specifies the request to send for client's upgrade.
func ServerConn ¶
ServerConn returns a new HTTP/2 server side connection using rawConn as the underlying transport. If config is nil, the default configuration is used.
func (*Conn) CloseTimeout ¶
CloseTimeout closes this connection by sending GOAWAY frame and waits for shutdown to finish.
The timeout parameter specifies a time duration this connection will wait for all streams to be closed before closing the connection.
If timeout is zero, it will close Immediately.
func (*Conn) GoAwayReceived ¶
func (c *Conn) GoAwayReceived() (bool, *GoAwayFrame)
GoAwayReceived returns whether or not a GOAWAY was received from the remote connection.
func (*Conn) GoAwaySent ¶
func (c *Conn) GoAwaySent() (bool, *GoAwayFrame)
GoAwaySent returns whether or not a GOAWAY was sent to the remote connection.
func (*Conn) Handshake ¶
Handshake runs the client or server handshake protocol if it has not yet been run. Most uses of this package need not call Handshake explicitly: the first Read or Write will call it automatically.
func (*Conn) InitialRecvWindow ¶
InitialRecvWindow returns the initial receive flow control window size for the given stream.
func (*Conn) InitialSendWindow ¶
InitialSendWindow returns the initial send flow control window size for the given stream.
func (*Conn) LastStreamID ¶
LastStreamID returns the ID of the remote-stream last successfully created.
func (*Conn) NextStreamID ¶
NextStreamID returns the next generated stream id.
func (*Conn) NumActiveStreams ¶
NumActiveStreams returns the number of active streams(OPEN or HALF CLOSED).
func (*Conn) RecvWindow ¶
RecvWindow returns the portion of the recieve flow control window for the given stream that is currently available for receiving frames which are subject to flow control.
func (*Conn) RemoteAddr ¶
RemoteAddr returns the remote network address.
func (*Conn) RemoteSettings ¶
RemoteSettings returns the remote-side http2settings.
func (*Conn) SendWindow ¶
SendWindow returns the portion of the send flow control window for the given stream that is currently available for sending frames which are subject to flow control.
func (*Conn) ServerConn ¶
ServerConn returns whether or not this connection is the server-side.
func (*Conn) WriteFrame ¶
WriteFrame writes a frame to the connection.
type ConnError ¶
ConnError represents connection error, defined in RFC 7540 section 5.4.1.
type DataFrame ¶
DataFrame represents the DATA frame, defined in RFC 7540 section 6.1.
func (*DataFrame) EndOfStream ¶
type Dialer ¶
type Dialer struct { // DialTCP specifies the dial function for creating unencrypted // TCP connections. // If DialTCP is nil, net.Dial is used. DialTCP func(network, addr string) (net.Conn, error) // DialTLS specifies an optional dial function for creating // TLS connections for non-proxied HTTPS requests. // // If DialTLS is nil, DialTCP and TLSClientConfig are used. // // If DialTLS is set, the TLSClientConfig are ignored. DialTLS func(network, addr string) (net.Conn, error) // Config specifies the connection configuration to use with // ClientConn. If nil, the default configuration is used. Config *Config // TLSClientConfig specifies the TLS configuration to use with // tls.Client. If nil, the default configuration is used. TLSClientConfig *tls.Config }
A Dialer contains options for connecting to HTTP/2 server.
func (*Dialer) Dial ¶
Dial connects to the address on the named protocol and then initiates a HTTP/2 negotiation, returning the resulting HTTP/2 connection.
Allowed protocols are "h2" (ALPN) and "h2c" (Upgrade).
The request parameter specifies an HTTP/1.1 request to send for client's upgrade.
If request is nil, default upgrade request are used.
If protocol is "h2", request are ignored.
Examples:
d.Dial("h2", "google.com:https", nil) d.Dial("h2c", "12.34.56.78:http", nil) d.Dial(http2.ProtocolTCP, request.Host, request)
type ErrCode ¶
type ErrCode uint32
ErrCode represents error codes, defined in RFC 7540 section 7.
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 Flags ¶
type Flags uint8
Flags is An 8-bit field reserved for boolean flags specific to the frame type.
type FrameType ¶
type FrameType uint8
FrameType represents Frame Type Registry, defined in RFC 7540 section 11.2.
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 )
type GoAwayFrame ¶
GoAwayFrame represents the GOAWAY frame, defined in RFC 7540 section 6.8.
func (*GoAwayFrame) EndOfStream ¶
func (f *GoAwayFrame) EndOfStream() bool
func (*GoAwayFrame) Stream ¶
func (f *GoAwayFrame) Stream() uint32
func (*GoAwayFrame) Type ¶
func (f *GoAwayFrame) Type() FrameType
type Handler ¶
type Handler func(*Conn)
A Handler for reading or writing frames from the connection.
type HandshakeError ¶
type HandshakeError string
HandshakeError represents connection handshake error.
func (HandshakeError) Error ¶
func (e HandshakeError) Error() string
type Header ¶
Header is A collection of headers sent or received via HTTP/2.
func (Header) SetAuthority ¶
SetAuthority sets the authority header.
type HeadersFrame ¶
HeadersFrame represents the HEADERS frame, defined in RFC 7540 section 6.2.
func (*HeadersFrame) EndOfStream ¶
func (f *HeadersFrame) EndOfStream() bool
func (*HeadersFrame) HasPriority ¶
func (f *HeadersFrame) HasPriority() bool
func (*HeadersFrame) Stream ¶
func (f *HeadersFrame) Stream() uint32
func (*HeadersFrame) Type ¶
func (f *HeadersFrame) Type() FrameType
type MalformedError ¶
type MalformedError string
MalformedError represents Malformed Requests and Responses, defined in RFC 7540 section 8.1.2.6.
func (MalformedError) Error ¶
func (e MalformedError) Error() string
type PingFrame ¶
PingFrame represents the PING frame, defined in RFC 7540 section 6.7.
func (*PingFrame) EndOfStream ¶
type PriorityFrame ¶
PriorityFrame represents the PRIORITY frame, defined in RFC 7540 section 6.3.
func (*PriorityFrame) EndOfStream ¶
func (f *PriorityFrame) EndOfStream() bool
func (*PriorityFrame) Stream ¶
func (f *PriorityFrame) Stream() uint32
func (*PriorityFrame) Type ¶
func (f *PriorityFrame) Type() FrameType
type PushPromiseFrame ¶
PushPromiseFrame represents the PUSH_PROMISE frame, defined in RFC 7540 section 6.6.
func (*PushPromiseFrame) EndOfStream ¶
func (f *PushPromiseFrame) EndOfStream() bool
func (*PushPromiseFrame) Stream ¶
func (f *PushPromiseFrame) Stream() uint32
func (*PushPromiseFrame) Type ¶
func (f *PushPromiseFrame) Type() FrameType
type RSTStreamFrame ¶
RSTStreamFrame represents the RST_STREAM frame, defined in RFC 7540 section 6.4.
func (*RSTStreamFrame) EndOfStream ¶
func (f *RSTStreamFrame) EndOfStream() bool
func (*RSTStreamFrame) Stream ¶
func (f *RSTStreamFrame) Stream() uint32
func (*RSTStreamFrame) Type ¶
func (f *RSTStreamFrame) Type() FrameType
type Server ¶
type Server struct { Addr string // TCP address to listen on, ":http" if empty Handler Handler // handler to invoke, cannot be nil Config *Config // optional connection config, used by ServerConn TLSConfig *tls.Config // optional TLS config, used by ListenAndServeTLS }
A Server defines parameters for running an HTTP/2 server.
func (*Server) ListenAndServe ¶
ListenAndServe listens on the TCP network address s.Addr and then calls Serve to handle requests on incoming connections. Accepted connections are configured to enable TCP no-delay. If s.Addr is blank, ":http" is used. ListenAndServe always returns a non-nil error.
func (*Server) ListenAndServeTLS ¶
ListenAndServeTLS listens on the TCP network address s.Addr and then calls Serve to handle requests on incoming TLS connections. Accepted connections are configured to enable TCP no-delay.
Filenames containing a certificate and matching private key for the server must be provided if the Server's TLSConfig.Certificates is not populated. If the certificate is signed by a certificate authority, the certFile should be the concatenation of the server's certificate, any intermediates, and the CA's certificate.
If s.Addr is blank, ":https" is used.
ListenAndServeTLS always returns a non-nil error.
type SettingID ¶
type SettingID uint16
SettingID represents SETTINGS Parameters, defined in RFC 7540 section 6.5.2.
type Settings ¶
type Settings []setting
Settings for local or remote in an HTTP/2 connection.
func (Settings) HeaderTableSize ¶
HeaderTableSize returns the SettingHeaderTableSize value.
func (Settings) InitialWindowSize ¶
InitialWindowSize returns the SettingInitialWindowSize value.
func (Settings) MaxConcurrentStreams ¶
MaxConcurrentStreams returns the SettingMaxConcurrentStreams value.
func (Settings) MaxFrameSize ¶
MaxFrameSize returns the SettingMaxFrameSize value.
func (Settings) MaxHeaderListSize ¶
MaxHeaderListSize returns the SettingMaxHeaderListSize value.
func (Settings) PushEnabled ¶
PushEnabled returns the SettingEnablePush value.
func (*Settings) SetHeaderTableSize ¶
SetHeaderTableSize sets the SettingHeaderTableSize value.
func (*Settings) SetInitialWindowSize ¶
SetInitialWindowSize sets the SettingInitialWindowSize value.
func (*Settings) SetMaxConcurrentStreams ¶
SetMaxConcurrentStreams sets the SettingMaxConcurrentStreams value.
func (*Settings) SetMaxFrameSize ¶
SetMaxFrameSize sets the SettingMaxFrameSize value.
func (*Settings) SetMaxHeaderListSize ¶
SetMaxHeaderListSize sets the SettingMaxHeaderListSize value.
func (*Settings) SetPushEnabled ¶
SetPushEnabled sets the SettingEnablePush value.
type SettingsFrame ¶
SettingsFrame represents the SETTINGS frame, defined in RFC 7540 section 6.5.
func (*SettingsFrame) EndOfStream ¶
func (f *SettingsFrame) EndOfStream() bool
func (*SettingsFrame) Stream ¶
func (f *SettingsFrame) Stream() uint32
func (*SettingsFrame) Type ¶
func (f *SettingsFrame) Type() FrameType
type StreamError ¶
StreamError represents stream error, defined in RFC 7540 section 5.4.2.
func (StreamError) Error ¶
func (e StreamError) Error() string
type StreamErrorList ¶
type StreamErrorList []*StreamError
StreamErrorList is a list of *StreamErrors.
func (StreamErrorList) Error ¶
func (e StreamErrorList) Error() string
type StreamState ¶
type StreamState int32
const ( StateIdle StreamState = iota StateReservedLocal StateReservedRemote StateOpen StateHalfClosedLocal StateHalfClosedRemote StateClosed )
func (StreamState) String ¶
func (state StreamState) String() string
type UnknownFrame ¶
UnknownFrame represents not defined by the HTTP/2 spec.
func (*UnknownFrame) EndOfStream ¶
func (f *UnknownFrame) EndOfStream() bool
func (*UnknownFrame) Stream ¶
func (f *UnknownFrame) Stream() uint32
func (*UnknownFrame) Type ¶
func (f *UnknownFrame) Type() FrameType
type WindowUpdateFrame ¶
WindowUpdateFrame represents the WINDOW_UPDATE frame, defined in RFC 7540 section 6.9.
func (*WindowUpdateFrame) EndOfStream ¶
func (f *WindowUpdateFrame) EndOfStream() bool
func (*WindowUpdateFrame) Stream ¶
func (f *WindowUpdateFrame) Stream() uint32
func (*WindowUpdateFrame) Type ¶
func (f *WindowUpdateFrame) Type() FrameType