Documentation ¶
Index ¶
- Constants
- Variables
- func HuffmanDecode(dst, src []byte) []byte
- func HuffmanEncode(dst, src []byte) []byte
- func NewError(code ErrorCode, msg string) error
- func ReadPreface(br io.Reader) bool
- func ReleaseContinuation(c *Continuation)
- func ReleaseData(data *Data)
- func ReleaseFrame(fr *Frame)
- func ReleaseGoAway(ga *GoAway)
- func ReleaseHPACK(hpack *HPACK)
- func ReleaseHeaderField(hf *HeaderField)
- func ReleaseHeaders(h *Headers)
- func ReleasePing(pp *Ping)
- func ReleasePriority(pry *Priority)
- func ReleasePushPromise(pp *PushPromise)
- func ReleaseRstStream(rst *RstStream)
- func ReleaseSettings(st *Settings)
- func ReleaseWindowUpdate(wu *WindowUpdate)
- func WritePreface(wr io.Writer) error
- type Client
- type ClientStream
- type Continuation
- func (c *Continuation) AppendHeader(b []byte)
- func (c *Continuation) CopyTo(cc *Continuation)
- func (c *Continuation) EndHeaders() bool
- func (c *Continuation) Header() []byte
- func (c *Continuation) ReadFrame(fr *Frame) (err error)
- func (c *Continuation) Reset()
- func (c *Continuation) SetEndHeaders(value bool)
- func (c *Continuation) SetHeader(b []byte)
- func (c *Continuation) Write(b []byte) (int, error)
- func (c *Continuation) WriteFrame(fr *Frame) error
- type Data
- func (data *Data) Append(b []byte)
- func (data *Data) CopyTo(d *Data)
- func (data *Data) Data() []byte
- func (data *Data) EndStream() bool
- func (data *Data) Len() uint32
- func (data *Data) Padding() bool
- func (data *Data) ReadFrame(fr *Frame) (err error)
- func (data *Data) Reset()
- func (data *Data) SetData(b []byte)
- func (data *Data) SetEndStream(value bool)
- func (data *Data) SetPadding(value bool)
- func (data *Data) Write(b []byte) (int, error)
- func (data *Data) WriteFrame(fr *Frame)
- type Error
- type ErrorCode
- type Frame
- func (fr *Frame) AddFlag(f FrameFlags)
- func (fr *Frame) AppendPayload(src []byte) (int, error)
- func (fr *Frame) DelFlag(f FrameFlags)
- func (fr *Frame) Flags() FrameFlags
- func (fr *Frame) HasFlag(f FrameFlags) bool
- func (fr *Frame) Len() uint32
- func (fr *Frame) MaxLen() uint32
- func (fr *Frame) Payload() []byte
- func (fr *Frame) ReadFrom(br *bufio.Reader) (int64, error)
- func (fr *Frame) ReadFromLimitPayload(br *bufio.Reader, max uint32) (int64, error)
- func (fr *Frame) Reset()
- func (fr *Frame) SetMaxLen(maxLen uint32)
- func (fr *Frame) SetPayload(b []byte) (err error)
- func (fr *Frame) SetStream(stream uint32)
- func (fr *Frame) SetType(kind FrameType)
- func (fr *Frame) Stream() uint32
- func (fr *Frame) Type() FrameType
- func (fr *Frame) Write(b []byte) (int, error)
- func (fr *Frame) WriteTo(w *bufio.Writer) (wb int64, err error)
- type FrameFlags
- type FrameType
- type GoAway
- func (ga *GoAway) Code() ErrorCode
- func (ga *GoAway) CopyTo(ga2 *GoAway)
- func (ga *GoAway) Data() []byte
- func (ga *GoAway) ReadFrame(fr *Frame) (err error)
- func (ga *GoAway) Reset()
- func (ga *GoAway) SetCode(code ErrorCode)
- func (ga *GoAway) SetData(b []byte)
- func (ga *GoAway) SetStream(stream uint32)
- func (ga *GoAway) Stream() uint32
- func (ga *GoAway) WriteFrame(fr *Frame) (err error)
- type HPACK
- type HTTP2ProtoError
- type HeaderField
- func (hf *HeaderField) AppendBytes(dst []byte) []byte
- func (hf *HeaderField) CopyTo(hf2 *HeaderField)
- func (hf *HeaderField) IsPseudo() bool
- func (hf *HeaderField) IsSensible() bool
- func (hf *HeaderField) Key() string
- func (hf *HeaderField) KeyBytes() []byte
- func (hf *HeaderField) Reset()
- func (hf *HeaderField) Set(k, v string)
- func (hf *HeaderField) SetBytes(k, v []byte)
- func (hf *HeaderField) SetKey(key string)
- func (hf *HeaderField) SetKeyBytes(key []byte)
- func (hf *HeaderField) SetValue(value string)
- func (hf *HeaderField) SetValueBytes(value []byte)
- func (hf *HeaderField) Size() int
- func (hf *HeaderField) Value() string
- func (hf *HeaderField) ValueBytes() []byte
- type Headers
- func (h *Headers) AppendRawHeaders(b []byte)
- func (h *Headers) CopyTo(h2 *Headers)
- func (h *Headers) EndHeaders() bool
- func (h *Headers) EndStream() bool
- func (h *Headers) Headers() []byte
- func (h *Headers) Padding() bool
- func (h *Headers) ReadFrame(fr *Frame) (err error)
- func (h *Headers) Reset()
- func (h *Headers) SetEndHeaders(value bool)
- func (h *Headers) SetEndStream(value bool)
- func (h *Headers) SetHeaders(b []byte)
- func (h *Headers) SetPadding(value bool)
- func (h *Headers) SetStream(stream uint32)
- func (h *Headers) SetWeight(w byte)
- func (h *Headers) Stream() uint32
- func (h *Headers) Weight() byte
- func (h *Headers) WriteFrame(fr *Frame) error
- type Options
- type Ping
- type Priority
- func (pry *Priority) CopyTo(p *Priority)
- func (pry *Priority) ReadFrame(fr *Frame) (err error)
- func (pry *Priority) Reset()
- func (pry *Priority) SetStream(stream uint32)
- func (pry *Priority) SetWeight(w byte)
- func (pry *Priority) Stream() uint32
- func (pry *Priority) Weight() byte
- func (pry *Priority) WriteFrame(fr *Frame)
- type PushPromise
- type RstStream
- type Server
- type ServerStream
- type Settings
- func (st *Settings) Clear()
- func (st *Settings) CopyTo(st2 *Settings)
- func (st *Settings) Encode()
- func (st *Settings) HeaderTableSize() uint32
- func (st *Settings) IsAck() bool
- func (st *Settings) MaxConcurrentStreams() uint32
- func (st *Settings) MaxFrameSize() uint32
- func (st *Settings) MaxHeaderListSize() uint32
- func (st *Settings) MaxWindowSize() uint32
- func (st *Settings) Push() bool
- func (st *Settings) Read(d []byte)
- func (st *Settings) ReadFrame(fr *Frame) error
- func (st *Settings) Reset()
- func (st *Settings) SetAck(ack bool)
- func (st *Settings) SetHeaderTableSize(size uint32)
- func (st *Settings) SetMaxConcurrentStreams(streams uint32)
- func (st *Settings) SetMaxFrameSize(size uint32)
- func (st *Settings) SetMaxHeaderListSize(size uint32)
- func (st *Settings) SetMaxWindowSize(size uint32)
- func (st *Settings) SetPush(value bool)
- func (st *Settings) WriteFrame(fr *Frame) error
- type StreamState
- type WindowUpdate
Constants ¶
const ( // FrameSettings string values (https://httpwg.org/specs/rfc7540.html#SettingValues) HeaderTableSize uint16 = 0x1 EnablePush uint16 = 0x2 MaxConcurrentStreams uint16 = 0x3 MaxWindowSize uint16 = 0x4 MaxFrameSize uint16 = 0x5 MaxHeaderListSize uint16 = 0x6 )
const ( // H2TLSProto is the string used in ALPN-TLS negotiation. H2TLSProto = "h2" // H2Clean is the string used in HTTP headers by the client to upgrade the connection. H2Clean = "h2c" )
Variables ¶
var ( // This error codes must be used with FrameGoAway ErrUnknowFrameType = errors.New("unknown frame type") ErrZeroPayload = errors.New("frame Payload len = 0") ErrMissingBytes = errors.New("missing payload bytes. Need more") ErrTooManyBytes = errors.New("too many bytes") ErrBadPreface = errors.New("wrong preface") ErrFrameMismatch = errors.New("frame type mismatch from called function") ErrNilWriter = errors.New("Writer cannot be nil") ErrNilReader = errors.New("Reader cannot be nil") ErrUnknown = errors.New("Unknown error") ErrBitOverflow = errors.New("Bit overflow") ErrPayloadExceeds = errors.New("Frame payload exceeds the negotiated maximum size") )
var ErrFieldNotFound = errors.New("field not found in neither table")
Functions ¶
func HuffmanDecode ¶
HuffmanDecode decodes src into dst using Huffman codes.
src and dst must not point to the same address.
func HuffmanEncode ¶
HuffmanEncode encodes src into dst using Huffman algorithm.
src and dst must not point to the same address.
func ReadPreface ¶
ReadPreface reads the connection initialisation preface.
func ReleaseHeaderField ¶
func ReleaseHeaderField(hf *HeaderField)
ReleaseHeaderField puts HeaderField to the pool.
func ReleasePriority ¶
func ReleasePriority(pry *Priority)
ReleasePriority retusn pry to the Priority frame pool.
func ReleaseSettings ¶
func ReleaseSettings(st *Settings)
ReleaseSettings puts st into settings pool to be reused in the future.
func WritePreface ¶
WritePreface writes HTTP/2 preface to the wr.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
func ConfigureClient ¶
func ConfigureClient(c *fasthttp.HostClient, opts ...Options) (*Client, error)
TODO: checkout https://github.com/golang/net/blob/4acb7895a057/http2/transport.go#L570
type ClientStream ¶
type ClientStream struct {
// contains filtered or unexported fields
}
func (*ClientStream) Close ¶
func (strm *ClientStream) Close()
type Continuation ¶
type Continuation struct {
// contains filtered or unexported fields
}
Continuation ...
https://tools.ietf.org/html/rfc7540#section-6.10
func (*Continuation) CopyTo ¶
func (c *Continuation) CopyTo(cc *Continuation)
func (*Continuation) ReadFrame ¶
func (c *Continuation) ReadFrame(fr *Frame) (err error)
ReadFrame reads decodes fr payload into c.
func (*Continuation) SetEndHeaders ¶
func (c *Continuation) SetEndHeaders(value bool)
SetEndHeaders ...
type Data ¶
type Data struct {
// contains filtered or unexported fields
}
Data defines a FrameData
Data frames can have the following flags: END_STREAM PADDED
https://tools.ietf.org/html/rfc7540#section-6.1
func (*Data) SetPadding ¶
SetPadding sets hasPaddingding to the data if true. If false the data won't be hasPaddingded.
func (*Data) WriteFrame ¶
WriteFrame writes the data to the frame payload setting FlagPadded.
This function only resets the frame payload.
type ErrorCode ¶
type ErrorCode uint32
const ( // Error codes (http://httpwg.org/specs/rfc7540.html#ErrorCodes) // // Errors must be uint32 because of FrameReset NoError ErrorCode = 0x0 ProtocolError ErrorCode = 0x1 InternalError ErrorCode = 0x2 FlowControlError ErrorCode = 0x3 SettingsTimeoutError ErrorCode = 0x4 StreamClosedError ErrorCode = 0x5 FrameSizeError ErrorCode = 0x6 RefusedStreamError ErrorCode = 0x7 CancelError ErrorCode = 0x8 CompressionError ErrorCode = 0x9 ConnectionError ErrorCode = 0xa EnhanceYourCalm ErrorCode = 0xb InadequateSecurity ErrorCode = 0xc HTTP11Required ErrorCode = 0xd )
type Frame ¶
type Frame struct {
// contains filtered or unexported fields
}
Frame is frame representation of HTTP2 protocol
Use AcquireFrame instead of creating Frame every time if you are going to use Frame as your own and ReleaseFrame to delete the Frame
Frame instance MUST NOT be used from different goroutines.
https://tools.ietf.org/html/rfc7540#section-4.1
func (*Frame) AppendPayload ¶
AppendPayload appends bytes to frame payload
If the result payload exceeds the max length ErrPayloadExceeds is returned. TODO: Split a frame if the length is exceeded
func (*Frame) Flags ¶
func (fr *Frame) Flags() FrameFlags
func (*Frame) HasFlag ¶
func (fr *Frame) HasFlag(f FrameFlags) bool
HasFlag returns if `f` is in the frame flags or not.
func (*Frame) ReadFrom ¶
ReadFrom reads frame from Reader.
This function returns readed bytes and/or error.
Unlike io.ReaderFrom this method does not read until io.EOF
func (*Frame) ReadFromLimitPayload ¶
ReadFromLimitPayload reads frame from reader limiting the payload.
func (*Frame) SetPayload ¶
SetPayload sets new payload to fr
This function returns ErrPayloadExceeds if payload length exceeds negotiated maximum size.
func (*Frame) SetStream ¶
SetStream sets the stream id on the current frame.
This function DOESN'T delete the reserved bit (first bit) in order to support personalized implementations of the protocol.
func (*Frame) Type ¶
Type returns the frame type (https://httpwg.org/specs/rfc7540.html#Frame_types)
type FrameFlags ¶
type FrameFlags int8
const ( // Frame Flag (described along the frame types) // More flags have been ignored due to redundancy FlagAck FrameFlags = 0x1 FlagEndStream FrameFlags = 0x1 FlagEndHeaders FrameFlags = 0x4 FlagPadded FrameFlags = 0x8 FlagPriority FrameFlags = 0x20 )
type FrameType ¶
type FrameType int8
const FrameContinuation FrameType = 0x9
const FrameData FrameType = 0x0
const FrameGoAway FrameType = 0x7
const FrameHeaders FrameType = 0x1
const FramePing FrameType = 0x6
const FramePriority FrameType = 0x2
const FramePushPromise FrameType = 0x5
const FrameResetStream FrameType = 0x3
const FrameSettings FrameType = 0x4
const FrameWindowUpdate FrameType = 0x8
type HPACK ¶
type HPACK struct { // DisableCompression disables compression for literal header fields. DisableCompression bool // DisableDynamicTable disables the usage of the dynamic table for // the HPACK structure. If this option is true the HPACK won't add any // field to the dynamic table unless it was sended by the peer. // // This field was implemented because in many ways the server could modify // the fields stablished by the client losing performance calculated by client. DisableDynamicTable bool // contains filtered or unexported fields }
HPACK represents header compression methods to encode and decode header fields in HTTP/2.
HPACK is equivalent to a HTTP/1 header.
Use AcquireHPACK to acquire new HPACK structure TODO: HPACK to Headers?
func (*HPACK) AppendHeader ¶
func (hpack *HPACK) AppendHeader(dst []byte, hf *HeaderField, store bool) []byte
AppendHeader appends the content of an encoded HeaderField to dst.
func (*HPACK) DynamicSize ¶
Dynamic size returns the size of the dynamic table. https://tools.ietf.org/html/rfc7541#section-4.1
func (*HPACK) Next ¶
func (hpack *HPACK) Next(hf *HeaderField, b []byte) ([]byte, error)
Next reads and process the content of `b`. If buf contains a valid HTTP/2 header the content will be parsed into `hf`.
This function returns the next byte slice that should be read. `b` must be a valid payload coming from a Header frame.
func (*HPACK) Reset ¶
func (hpack *HPACK) Reset()
Reset deletes and releases all dynamic header fields
func (*HPACK) SetMaxTableSize ¶
SetMaxTableSize sets the maximum dynamic table size.
type HTTP2ProtoError ¶
func NewHTTP2ProtoError ¶
func NewHTTP2ProtoError(code int, reason string) *HTTP2ProtoError
func (*HTTP2ProtoError) Error ¶
func (pe *HTTP2ProtoError) Error() string
type HeaderField ¶
type HeaderField struct {
// contains filtered or unexported fields
}
HeaderField represents a field in HPACK tables.
Use AcquireHeaderField to acquire HeaderField.
func AcquireHeaderField ¶
func AcquireHeaderField() *HeaderField
AcquireHeaderField gets HeaderField from the pool.
func (*HeaderField) AppendBytes ¶
func (hf *HeaderField) AppendBytes(dst []byte) []byte
AppendBytes appends header representation of hf to dst and returns the new dst.
func (*HeaderField) CopyTo ¶
func (hf *HeaderField) CopyTo(hf2 *HeaderField)
CopyTo copies hf to hf2
func (*HeaderField) IsPseudo ¶
func (hf *HeaderField) IsPseudo() bool
IsPseudo returns true if field is pseudo header
func (*HeaderField) IsSensible ¶
func (hf *HeaderField) IsSensible() bool
IsSensible returns if header field have been marked as sensible.
func (*HeaderField) KeyBytes ¶
func (hf *HeaderField) KeyBytes() []byte
KeyBytes returns the key bytes of the field.
func (*HeaderField) Set ¶
func (hf *HeaderField) Set(k, v string)
func (*HeaderField) SetBytes ¶
func (hf *HeaderField) SetBytes(k, v []byte)
func (*HeaderField) SetKey ¶
func (hf *HeaderField) SetKey(key string)
SetKey sets key to the field.
func (*HeaderField) SetKeyBytes ¶
func (hf *HeaderField) SetKeyBytes(key []byte)
SetKeyString sets key to the field.
func (*HeaderField) SetValue ¶
func (hf *HeaderField) SetValue(value string)
SetValue sets value to the field.
func (*HeaderField) SetValueBytes ¶
func (hf *HeaderField) SetValueBytes(value []byte)
SetValueString sets value to the field.
func (*HeaderField) Size ¶
func (hf *HeaderField) Size() int
Size returns the header field size as RFC specifies.
func (*HeaderField) Value ¶
func (hf *HeaderField) Value() string
Value returns the value of the field
func (*HeaderField) ValueBytes ¶
func (hf *HeaderField) ValueBytes() []byte
ValueBytes returns the value bytes of the field.
type Headers ¶
type Headers struct {
// contains filtered or unexported fields
}
Headers defines a FrameHeaders
https://tools.ietf.org/html/rfc7540#section-6.2
func (*Headers) AppendRawHeaders ¶
AppendRawHeaders appends b to the raw headers.
func (*Headers) ReadFrame ¶
ReadFrame reads header data from fr.
This function appends over rawHeaders .....
func (*Headers) SetPadding ¶
SetPadding sets hasPaddingding value ...
func (*Headers) WriteFrame ¶
type Priority ¶
type Priority struct {
// contains filtered or unexported fields
}
Priority represents the Priority frame.
https://tools.ietf.org/html/rfc7540#section-6.3
func AcquirePriority ¶
func AcquirePriority() *Priority
AcquirePriority gets priority structure from pool.
func (*Priority) WriteFrame ¶
WriteFrame writes pry to the Freame. The Frame payload is resetted.
type PushPromise ¶
type PushPromise struct {
// contains filtered or unexported fields
}
PushPromise ...
https://tools.ietf.org/html/rfc7540#section-6.6
func (*PushPromise) ReadFrame ¶
func (pp *PushPromise) ReadFrame(fr *Frame) (err error)
ReadFrame ...
func (*PushPromise) SetHeader ¶
func (pp *PushPromise) SetHeader(h []byte)
func (*PushPromise) WriteFrame ¶
func (pp *PushPromise) WriteFrame(fr *Frame) (err error)
WriteFrame ...
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server ...
TODO: Shared windowSize
func ConfigureServer ¶
ConfigureServer configures the fasthttp's server to handle HTTP/2 connections. The HTTP/2 connection can be only established if the fasthttp server is using TLS.
Future implementations may support HTTP/2 through plain TCP.
type ServerStream ¶
type ServerStream struct {
// contains filtered or unexported fields
}
func (*ServerStream) IsClosed ¶
func (strm *ServerStream) IsClosed() bool
func (*ServerStream) State ¶
func (strm *ServerStream) State() StreamState
type Settings ¶
type Settings struct {
// contains filtered or unexported fields
}
Settings is the options to establish between endpoints when starting the connection.
This options have been humanize.
func AcquireSettings ¶
func AcquireSettings() *Settings
AcquireSettings gets a Settings object from the pool with default values.
func (*Settings) Encode ¶
func (st *Settings) Encode()
Encode encodes settings to be sent through the wire
func (*Settings) HeaderTableSize ¶
HeaderTableSize returns the maximum size of the header compression table used to decode header blocks.
Default value is 4096
func (*Settings) MaxConcurrentStreams ¶
MaxConcurrentStreams returns the maximum number of concurrent Streams that the sender will allow.
Default value is 100. This value does not have max limit.
func (*Settings) MaxFrameSize ¶
MaxFrameSize returns the size of the largest frame Payload that the sender is willing to receive.
Default value is 1 << 14 Maximum value is 1 << 24 - 1
func (*Settings) MaxHeaderListSize ¶
MaxFrameSize returns maximum size of header list.
If this value is 0 indicates that there are no limit.
func (*Settings) MaxWindowSize ¶
MaxWindowSize returns the sender's initial window size for Stream-level flow control.
Default value is 1 << 16 - 1 Maximum value is 1 << 31 - 1
func (*Settings) SetHeaderTableSize ¶
SetHeaderTableSize sets the maximum size of the header compression table used to decode header blocks.
Default value is 4096
func (*Settings) SetMaxConcurrentStreams ¶
SetMaxConcurrentStreams sets the maximum number of concurrent Streams that the sender will allow.
Default value is 100. This value does not have max limit.
func (*Settings) SetMaxFrameSize ¶
SetMaxFrameSize sets the size of the largest frame Payload that the sender is willing to receive.
Default value is 1 << 14 Maximum value is 1 << 24 - 1
func (*Settings) SetMaxHeaderListSize ¶
SetMaxFrameSize sets maximum size of header list.
If this value is 0 indicates that there are no limit.
func (*Settings) SetMaxWindowSize ¶
SetMaxWindowSize sets the sender's initial window size for Stream-level flow control.
Default value is 1 << 16 - 1 Maximum value is 1 << 31 - 1
func (*Settings) SetPush ¶
SetPush allows to set the PushPromise settings.
If value is true the Push Promise will be enable. if not the Push Promise will be disabled.
func (*Settings) WriteFrame ¶
WriteFrame writes the settings frame into the frame payload
type StreamState ¶
type StreamState int8
const ( StateIdle StreamState = iota StateReserved StateOpen StateHalfClosed StateClosed )
func (StreamState) String ¶
func (s StreamState) String() string
type WindowUpdate ¶
type WindowUpdate struct {
// contains filtered or unexported fields
}
WindowUpdate ...
https://tools.ietf.org/html/rfc7540#section-6.9
func (*WindowUpdate) SetIncrement ¶
func (wu *WindowUpdate) SetIncrement(increment uint32)
SetIncrement ...