http2

package module
v0.2.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 29, 2021 License: Apache-2.0 Imports: 17 Imported by: 46

README

HTTP2

http2 is a implementation of HTTP/2 protocol for fasthttp.

Download

go get github.com/dgrr/http2@v0.1.1

Help

If you need any help setting up, contributing or understanding this repo, you can contact me on gofiber's Discord.

How to use the server?

The server can only be used if your server supports TLS. Then, you can call ConfigureServer.

import (
	"github.com/valyala/fasthttp"
	"github.com/dgrr/http2"
)

func main() {
    s := &fasthttp.Server{
        Handler: yourHandler,
        Name:    "HTTP2 test",
    }

    http2.ConfigureServer(s)
    
    s.ListenAndServeTLS(...)
}

How to use the client?

The HTTP/2 client only works with the HostClient.

package main

import (
        "fmt"
        "log"

        "github.com/dgrr/http2"
        "github.com/valyala/fasthttp"
)

func main() {
        hc := &fasthttp.HostClient{
                Addr:  "api.binance.com:443",
        }

        if err := http2.ConfigureClient(hc, http2.ClientOpts{}); err != nil {
                log.Printf("%s doesn't support http/2\n", hc.Addr)
        }

        statusCode, body, err := hc.Get(nil, "https://api.binance.com/api/v3/time")
        if err != nil {
                log.Fatalln(err)
        }

        fmt.Printf("%d: %s\n", statusCode, body)
}

Documentation

Index

Constants

View Source
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
)
View Source
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"
)
View Source
const DefaultPingInterval = time.Second * 5

Variables

View Source
var (

	// This error codes must be used with FrameGoAway
	ErrUnknowFrameType = NewError(
		ProtocolError, "unknown frame type")
	ErrMissingBytes = NewError(
		ProtocolError, "missing payload bytes. Need more")
	ErrPayloadExceeds = NewError(
		ProtocolError, "FrameHeader payload exceeds the negotiated maximum size")
)
View Source
var (
	StringPath          = []byte(":path")
	StringStatus        = []byte(":status")
	StringAuthority     = []byte(":authority")
	StringScheme        = []byte(":scheme")
	StringMethod        = []byte(":method")
	StringServer        = []byte("server")
	StringContentLength = []byte("content-length")
	StringContentType   = []byte("content-type")
	StringUserAgent     = []byte("user-agent")
	StringGzip          = []byte("gzip")
	StringGET           = []byte("GET")
	StringHEAD          = []byte("HEAD")
	StringPOST          = []byte("POST")
	StringHTTP2         = []byte("HTTP/2")
)
View Source
var ErrNotAvailableStreams = errors.New("ran out of available streams")
View Source
var (
	// ErrServerSupport indicates whether the server supports HTTP/2 or not.
	ErrServerSupport = errors.New("server doesn't support HTTP/2")
)

Functions

func ConfigureClient added in v0.0.8

func ConfigureClient(c *fasthttp.HostClient, opts ClientOpts) error

ConfigureClient configures the fasthttp.HostClient to run over HTTP/2.

func Handshake

func Handshake(preface bool, bw *bufio.Writer, st *Settings, maxWin int32) error

Handshake performs an HTTP/2 handshake. That means, it will send the preface if `preface` is true, send a settings frame and a window update frame (for the connection's window).

func HuffmanDecode

func HuffmanDecode(dst, src []byte) []byte

HuffmanDecode decodes src into dst using Huffman codes.

src and dst must not point to the same address.

func HuffmanEncode

func HuffmanEncode(dst, src []byte) []byte

HuffmanEncode encodes src into dst using Huffman algorithm.

src and dst must not point to the same address.

func ReadPreface

func ReadPreface(br io.Reader) bool

ReadPreface reads the connection initialisation preface.

func ReleaseFrame

func ReleaseFrame(fr Frame)

func ReleaseFrameHeader

func ReleaseFrameHeader(fr *FrameHeader)

ReleaseFrameHeader reset and puts fr to the pool.

func ReleaseHPACK

func ReleaseHPACK(hp *HPACK)

ReleaseHPACK puts HPACK to the pool

func ReleaseHeaderField

func ReleaseHeaderField(hf *HeaderField)

ReleaseHeaderField puts HeaderField to the pool.

func ToLower

func ToLower(b []byte) []byte

func WritePreface

func WritePreface(wr io.Writer) error

WritePreface writes HTTP/2 preface to the wr.

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client ...

func (*Client) Do added in v0.0.8

func (cl *Client) Do(req *fasthttp.Request, res *fasthttp.Response) (err error)

type ClientOpts added in v0.0.8

type ClientOpts struct {
	// PingInterval defines the interval in which the client will ping the server.
	//
	// An interval of 0 will make the library to use DefaultPingInterval. Because ping intervals can't be disabled.
	PingInterval time.Duration

	// OnRTT is assigned to every client after creation, and the handler
	// will be called after every RTT measurement (after receiving a PONG mesage).
	OnRTT func(time.Duration)
}

ClientOpts defines the client options for the HTTP/2 connection.

type Conn added in v0.0.8

type Conn struct {
	// contains filtered or unexported fields
}

Conn represents a raw HTTP/2 connection over TLS + TCP.

func NewConn added in v0.1.11

func NewConn(c net.Conn, opts ConnOpts) *Conn

NewConn returns a new HTTP/2 connection. To start using the connection you need to call Handshake.

func (*Conn) CanOpenStream added in v0.0.8

func (c *Conn) CanOpenStream() bool

CanOpenStream returns whether the client will be able to open a new stream or not.

func (*Conn) Close added in v0.0.8

func (c *Conn) Close() error

Close closes the connection gracefully, sending a GoAway message and then closing the underlying TCP connection.

func (*Conn) Closed added in v0.0.8

func (c *Conn) Closed() bool

Closed indicates whether the connection is closed or not.

func (*Conn) Handshake added in v0.1.11

func (c *Conn) Handshake() error

Handshake will perform the necessary handshake to establish the connection with the server. If an error is returned you can assume the TCP connection has been closed.

func (*Conn) LastErr added in v0.1.13

func (c *Conn) LastErr() error

LastErr returns the last registered error in case the connection was closed by the server.

func (*Conn) SetOnDisconnect added in v0.2.1

func (c *Conn) SetOnDisconnect(cb func(*Conn))

SetOnDisconnect sets the callback that will fire when the HTTP/2 connection is closed.

func (*Conn) Write added in v0.0.8

func (c *Conn) Write(r *Ctx)

Write queues the request to be sent to the server.

Check if `c` has been previously closed before accessing this function.

type ConnOpts added in v0.1.14

type ConnOpts struct {
	// PingInterval defines the interval in which the client will ping the server.
	//
	// An interval of 0 will make the library to use DefaultPingInterval. Because ping intervals can't be disabled
	PingInterval time.Duration
	// OnDisconnect is a callback that fires when the Conn disconnects.
	OnDisconnect func(c *Conn)
}

ConnOpts defines the connection options.

type Continuation

type Continuation struct {
	// contains filtered or unexported fields
}

Continuation represents the Continuation frame.

Continuation frame can carry raw headers and/or the EndHeaders flag.

https://tools.ietf.org/html/rfc7540#section-6.10

func (*Continuation) AppendHeader

func (c *Continuation) AppendHeader(b []byte)

AppendHeader appends the contents of `b` into the header.

func (*Continuation) CopyTo

func (c *Continuation) CopyTo(cc *Continuation)

func (*Continuation) Deserialize

func (c *Continuation) Deserialize(fr *FrameHeader) error

func (*Continuation) EndHeaders

func (c *Continuation) EndHeaders() bool

func (*Continuation) Headers

func (c *Continuation) Headers() []byte

Headers returns Header bytes.

func (*Continuation) Reset

func (c *Continuation) Reset()

Reset ...

func (*Continuation) Serialize

func (c *Continuation) Serialize(fr *FrameHeader)

func (*Continuation) SetEndHeaders

func (c *Continuation) SetEndHeaders(value bool)

SetEndHeaders ...

func (*Continuation) SetHeader

func (c *Continuation) SetHeader(b []byte)

SetHeader ...

func (*Continuation) Type

func (c *Continuation) Type() FrameType

func (*Continuation) Write

func (c *Continuation) Write(b []byte) (int, error)

Write writes `b` into the header. Write is equivalent to AppendHeader.

type Ctx added in v0.0.8

type Ctx struct {
	// Request ...
	Request *fasthttp.Request
	// Response ...
	Response *fasthttp.Response
	// Err ...
	Err chan error
}

Ctx represents a context for a stream. Every stream is related to a context.

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) Append

func (data *Data) Append(b []byte)

Append appends b to data

func (*Data) CopyTo

func (data *Data) CopyTo(d *Data)

CopyTo copies data to d.

func (*Data) Data

func (data *Data) Data() []byte

Data returns the byte slice of the data readed/to be sendStream.

func (*Data) Deserialize

func (data *Data) Deserialize(fr *FrameHeader) (err error)

func (*Data) EndStream

func (data *Data) EndStream() bool

func (*Data) Len

func (data *Data) Len() int

func (*Data) Padding

func (data *Data) Padding() bool

Padding returns true if the data will be/was hasPaddingded.

func (*Data) Reset

func (data *Data) Reset()

Reset ...

func (*Data) Serialize

func (data *Data) Serialize(fr *FrameHeader)

func (*Data) SetData

func (data *Data) SetData(b []byte)

SetData resets data byte slice and sets b.

func (*Data) SetEndStream

func (data *Data) SetEndStream(value bool)

SetEndStream ...

func (*Data) SetPadding

func (data *Data) SetPadding(value bool)

SetPadding sets hasPaddingding to the data if true. If false the data won't be hasPaddingded.

func (*Data) Type

func (data *Data) Type() FrameType

func (*Data) Write

func (data *Data) Write(b []byte) (int, error)

Write writes b to data

type Dialer added in v0.0.8

type Dialer struct {
	// Addr is the server's address in the form: `host:port`.
	Addr string

	// TLSConfig is the tls configuration.
	//
	// If TLSConfig is nil, a default one will be defined on the Dial call.
	TLSConfig *tls.Config

	// PingInterval defines the interval in which the client will ping the server.
	//
	// An interval of 0 will make the library to use DefaultPingInterval. Because ping intervals can't be disabled.
	PingInterval time.Duration
}

Dialer allows to create HTTP/2 connections by specifying an address and tls configuration.

func (*Dialer) Dial added in v0.0.8

func (d *Dialer) Dial(opts ConnOpts) (*Conn, error)

Dial creates an HTTP/2 connection or returns an error.

An expected error is ErrServerSupport.

type Error

type Error struct {
	// contains filtered or unexported fields
}

Error defines the HTTP/2 errors, composed by the code and debug data.

func NewError

func NewError(e ErrorCode, debug string) Error

NewError creates a new Error.

func (Error) Code

func (e Error) Code() ErrorCode

Code returns the error code.

func (Error) Debug added in v0.2.2

func (e Error) Debug() string

Debug returns the debug string.

func (Error) Error

func (e Error) Error() string

Error implements the error interface.

func (Error) Is added in v0.2.2

func (e Error) Is(target error) bool

Is implements the interface for errors.Is.

type ErrorCode

type ErrorCode uint32

ErrorCode defines the HTTP/2 error codes:

Error codes are defined here http://httpwg.org/specs/rfc7540.html#ErrorCodes

Errors must be uint32 because of FrameReset

const (
	NoError              ErrorCode = 0x0
	ProtocolError        ErrorCode = 0x1
	InternalError        ErrorCode = 0x2
	FlowControlError     ErrorCode = 0x3
	SettingsTimeoutError ErrorCode = 0x4
	StreamClosedError    ErrorCode = 0x5
	FrameSizeError       ErrorCode = 0x6
	RefusedStreamError   ErrorCode = 0x7
	StreamCancelled      ErrorCode = 0x8
	CompressionError     ErrorCode = 0x9
	ConnectionError      ErrorCode = 0xa
	EnhanceYourCalm      ErrorCode = 0xb
	InadequateSecurity   ErrorCode = 0xc
	HTTP11Required       ErrorCode = 0xd
)

func (ErrorCode) Error

func (e ErrorCode) Error() string

Error implements the error interface.

type Frame

type Frame interface {
	Type() FrameType
	Reset()

	Serialize(*FrameHeader)
	Deserialize(*FrameHeader) error
}

func AcquireFrame

func AcquireFrame(ftype FrameType) Frame

type FrameFlags

type FrameFlags int8
const (
	// FrameHeader default size
	// http://httpwg.org/specs/rfc7540.html#FrameHeader
	DefaultFrameSize = 9

	// 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
)

func (FrameFlags) Add

func (flags FrameFlags) Add(f FrameFlags) FrameFlags

Add adds a flag to frame flags.

func (FrameFlags) Del

func (flags FrameFlags) Del(f FrameFlags) FrameFlags

Del deletes f from frame flags

func (FrameFlags) Has

func (flags FrameFlags) Has(f FrameFlags) bool

Has returns if `f` is in the frame flags or not.

type FrameHeader

type FrameHeader struct {
	// contains filtered or unexported fields
}

FrameHeader is frame representation of HTTP2 protocol

Use AcquireFrameHeader instead of creating FrameHeader every time if you are going to use FrameHeader as your own and ReleaseFrameHeader to delete the FrameHeader

FrameHeader instance MUST NOT be used from different goroutines.

https://tools.ietf.org/html/rfc7540#section-4.1

func AcquireFrameHeader

func AcquireFrameHeader() *FrameHeader

AcquireFrameHeader gets a FrameHeader from pool.

func ReadFrameFrom

func ReadFrameFrom(br *bufio.Reader) (*FrameHeader, error)

ReadFrameFrom ...

func (*FrameHeader) Body

func (frh *FrameHeader) Body() Frame

Body ...

func (*FrameHeader) Flags

func (frh *FrameHeader) Flags() FrameFlags

Flags ...

func (*FrameHeader) Len

func (frh *FrameHeader) Len() int

Len returns the payload length

func (*FrameHeader) MaxLen

func (frh *FrameHeader) MaxLen() uint32

MaxLen returns max negotiated payload length.

func (*FrameHeader) ReadFrom

func (frh *FrameHeader) ReadFrom(br *bufio.Reader) (int64, error)

ReadFrom reads frame from Reader.

This function returns read bytes and/or error.

Unlike io.ReaderFrom this method does not read until io.EOF

func (*FrameHeader) ReadFromLimitPayload

func (frh *FrameHeader) ReadFromLimitPayload(br *bufio.Reader, max uint32) (int64, error)

ReadFromLimitPayload reads frame from reader limiting the payload.

func (*FrameHeader) Reset

func (frh *FrameHeader) Reset()

Reset resets header values.

func (*FrameHeader) SetBody

func (frh *FrameHeader) SetBody(fr Frame)

func (*FrameHeader) SetFlags

func (frh *FrameHeader) SetFlags(flags FrameFlags)

func (*FrameHeader) SetStream

func (frh *FrameHeader) SetStream(stream uint32)

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 (*FrameHeader) Stream

func (frh *FrameHeader) Stream() uint32

Stream returns the stream id of the current frame.

func (*FrameHeader) Type

func (frh *FrameHeader) Type() FrameType

Type returns the frame type (https://httpwg.org/specs/rfc7540.html#Frame_types)

func (*FrameHeader) WriteTo

func (frh *FrameHeader) WriteTo(w *bufio.Writer) (wb int64, err error)

WriteTo writes frame to the Writer.

This function returns FrameHeader bytes written and/or error.

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

func (FrameType) String

func (ft FrameType) String() string

type FrameWithHeaders

type FrameWithHeaders interface {
	Headers() []byte
}

type GoAway

type GoAway struct {
	// contains filtered or unexported fields
}

GoAway ...

https://tools.ietf.org/html/rfc7540#section-6.8

func (*GoAway) Code

func (ga *GoAway) Code() ErrorCode

Code ...

func (*GoAway) Copy added in v0.1.13

func (ga *GoAway) Copy() *GoAway

func (*GoAway) CopyTo

func (ga *GoAway) CopyTo(other *GoAway)

CopyTo ...

func (*GoAway) Data

func (ga *GoAway) Data() []byte

Data ...

func (*GoAway) Deserialize

func (ga *GoAway) Deserialize(fr *FrameHeader) (err error)

Deserialize ...

func (*GoAway) Error added in v0.1.13

func (ga *GoAway) Error() string

func (*GoAway) Reset

func (ga *GoAway) Reset()

Reset ...

func (*GoAway) Serialize

func (ga *GoAway) Serialize(fr *FrameHeader)

func (*GoAway) SetCode

func (ga *GoAway) SetCode(code ErrorCode)

SetCode ...

func (*GoAway) SetData

func (ga *GoAway) SetData(b []byte)

SetData ...

func (*GoAway) SetStream

func (ga *GoAway) SetStream(stream uint32)

SetStream ...

func (*GoAway) Stream

func (ga *GoAway) Stream() uint32

Stream ...

func (*GoAway) Type

func (ga *GoAway) Type() FrameType

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 AcquireHPACK

func AcquireHPACK() *HPACK

AcquireHPACK gets HPACK from pool

func (*HPACK) AppendHeader

func (hp *HPACK) AppendHeader(dst []byte, hf *HeaderField, store bool) []byte

AppendHeader appends the content of an encoded HeaderField to dst.

func (*HPACK) AppendHeaderField

func (hp *HPACK) AppendHeaderField(h *Headers, hf *HeaderField, store bool)

TODO: Change naming

func (*HPACK) DynamicSize

func (hp *HPACK) DynamicSize() (n int)

DynamicSize returns the size of the dynamic table.

https://tools.ietf.org/html/rfc7541#section-4.1

func (*HPACK) Next

func (hp *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 (hp *HPACK) Reset()

Reset deletes and releases all dynamic header fields

func (*HPACK) SetMaxTableSize

func (hp *HPACK) SetMaxTableSize(size int)

SetMaxTableSize sets the maximum dynamic table size.

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(other *HeaderField)

CopyTo copies the HeaderField to `other`.

func (*HeaderField) Empty added in v0.0.5

func (hf *HeaderField) Empty() bool

Empty returns true if `hf` doesn't contain any key nor value.

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) Key

func (hf *HeaderField) Key() string

Key returns the key of the field

func (*HeaderField) KeyBytes

func (hf *HeaderField) KeyBytes() []byte

KeyBytes returns the key bytes of the field.

func (*HeaderField) Reset

func (hf *HeaderField) Reset()

Reset resets header field values.

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.

https://tools.ietf.org/html/rfc7541#section-4.1

func (*HeaderField) String added in v0.1.15

func (hf *HeaderField) String() string

String returns a string representation of the header field.

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) AppendHeaderField

func (h *Headers) AppendHeaderField(hp *HPACK, hf *HeaderField, store bool)

func (*Headers) AppendRawHeaders

func (h *Headers) AppendRawHeaders(b []byte)

AppendRawHeaders appends b to the raw headers.

func (*Headers) CopyTo

func (h *Headers) CopyTo(h2 *Headers)

CopyTo copies h fields to h2.

func (*Headers) Deserialize

func (h *Headers) Deserialize(frh *FrameHeader) (err error)

func (*Headers) EndHeaders

func (h *Headers) EndHeaders() bool

EndHeaders ...

func (*Headers) EndStream

func (h *Headers) EndStream() bool

EndStream ...

func (*Headers) Headers

func (h *Headers) Headers() []byte

Headers ...

func (*Headers) Padding

func (h *Headers) Padding() bool

Padding ...

func (*Headers) Reset

func (h *Headers) Reset()

Reset ...

func (*Headers) Serialize

func (h *Headers) Serialize(frh *FrameHeader)

func (*Headers) SetEndHeaders

func (h *Headers) SetEndHeaders(value bool)

SetEndHeaders ...

func (*Headers) SetEndStream

func (h *Headers) SetEndStream(value bool)

SetEndStream ...

func (*Headers) SetHeaders

func (h *Headers) SetHeaders(b []byte)

SetHeaders ...

func (*Headers) SetPadding

func (h *Headers) SetPadding(value bool)

SetPadding ...

func (*Headers) SetStream

func (h *Headers) SetStream(stream uint32)

SetStream ...

func (*Headers) SetWeight

func (h *Headers) SetWeight(w byte)

SetWeight ...

func (*Headers) Stream

func (h *Headers) Stream() uint32

Stream ...

func (*Headers) Type

func (h *Headers) Type() FrameType

func (*Headers) Weight

func (h *Headers) Weight() byte

Weight ...

type Ping

type Ping struct {
	// contains filtered or unexported fields
}

Ping ...

https://tools.ietf.org/html/rfc7540#section-6.7

func (*Ping) CopyTo

func (p *Ping) CopyTo(other *Ping)

CopyTo ...

func (*Ping) Data

func (p *Ping) Data() []byte

func (*Ping) DataAsTime

func (p *Ping) DataAsTime() time.Time

func (*Ping) Deserialize

func (p *Ping) Deserialize(frh *FrameHeader) error

Deserialize ...

func (*Ping) IsAck

func (p *Ping) IsAck() bool

func (*Ping) Reset

func (p *Ping) Reset()

Reset ...

func (*Ping) Serialize

func (p *Ping) Serialize(fr *FrameHeader)

Serialize ...

func (*Ping) SetAck added in v0.0.8

func (p *Ping) SetAck(ack bool)

func (*Ping) SetCurrentTime

func (p *Ping) SetCurrentTime()

func (*Ping) SetData

func (p *Ping) SetData(b []byte)

SetData ...

func (*Ping) Type

func (p *Ping) Type() FrameType

func (*Ping) Write

func (p *Ping) Write(b []byte) (n int, err error)

Write ...

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 (*Priority) CopyTo

func (pry *Priority) CopyTo(p *Priority)

CopyTo ...

func (*Priority) Deserialize

func (pry *Priority) Deserialize(fr *FrameHeader) (err error)

func (*Priority) Reset

func (pry *Priority) Reset()

Reset resets priority fields.

func (*Priority) Serialize

func (pry *Priority) Serialize(fr *FrameHeader)

func (*Priority) SetStream

func (pry *Priority) SetStream(stream uint32)

SetStream sets the Priority frame stream.

func (*Priority) SetWeight

func (pry *Priority) SetWeight(w byte)

SetWeight sets the Priority frame weight.

func (*Priority) Stream

func (pry *Priority) Stream() uint32

Stream returns the Priority frame stream.

func (*Priority) Type

func (pry *Priority) Type() FrameType

func (*Priority) Weight

func (pry *Priority) Weight() byte

Weight returns the Priority frame weight.

type PushPromise

type PushPromise struct {
	// contains filtered or unexported fields
}

PushPromise ...

https://tools.ietf.org/html/rfc7540#section-6.6

func (*PushPromise) Deserialize

func (pp *PushPromise) Deserialize(fr *FrameHeader) (err error)

func (*PushPromise) Reset

func (pp *PushPromise) Reset()

Reset ...

func (*PushPromise) Serialize

func (pp *PushPromise) Serialize(fr *FrameHeader)

func (*PushPromise) SetHeader

func (pp *PushPromise) SetHeader(h []byte)

func (*PushPromise) Type

func (pp *PushPromise) Type() FrameType

func (*PushPromise) Write

func (pp *PushPromise) Write(b []byte) (int, error)

type RstStream

type RstStream struct {
	// contains filtered or unexported fields
}

RstStream ...

https://tools.ietf.org/html/rfc7540#section-6.4

func (*RstStream) Code

func (rst *RstStream) Code() ErrorCode

func (*RstStream) CopyTo

func (rst *RstStream) CopyTo(r *RstStream)

func (*RstStream) Deserialize

func (rst *RstStream) Deserialize(fr *FrameHeader) error

func (*RstStream) Error

func (rst *RstStream) Error() error

func (*RstStream) Reset

func (rst *RstStream) Reset()

func (*RstStream) Serialize

func (rst *RstStream) Serialize(fr *FrameHeader)

func (*RstStream) SetCode

func (rst *RstStream) SetCode(code ErrorCode)

func (*RstStream) Type

func (rst *RstStream) Type() FrameType

type Server

type Server struct {
	// contains filtered or unexported fields
}

func ConfigureServer added in v0.1.0

func ConfigureServer(s *fasthttp.Server) *Server

ConfigureServer configures the fasthttp 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.

func ConfigureServerAndConfig added in v0.1.0

func ConfigureServerAndConfig(s *fasthttp.Server, tlsConfig *tls.Config) *Server

ConfigureServerAndConfig configures the fasthttp server to handle HTTP/2 connections and your own tlsConfig file. If you are NOT using your own tls config, you may want to use ConfigureServer.

func (*Server) ServeConn

func (s *Server) ServeConn(c net.Conn) error

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 (*Settings) Clear

func (st *Settings) Clear()

func (*Settings) CopyTo

func (st *Settings) CopyTo(st2 *Settings)

CopyTo copies st fields to st2

func (*Settings) Deserialize

func (st *Settings) Deserialize(fr *FrameHeader) error

func (*Settings) Encode

func (st *Settings) Encode()

Encode encodes settings to be sent through the wire

func (*Settings) HeaderTableSize

func (st *Settings) HeaderTableSize() uint32

HeaderTableSize returns the maximum size of the header compression table used to decode header blocks.

Default value is 4096

func (*Settings) IsAck

func (st *Settings) IsAck() bool

IsAck returns true if settings has FlagAck set.

func (*Settings) MaxConcurrentStreams

func (st *Settings) MaxConcurrentStreams() uint32

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

func (st *Settings) MaxFrameSize() uint32

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

func (st *Settings) MaxHeaderListSize() uint32

MaxFrameSize returns maximum size of header list.

If this value is 0 indicates that there are no limit.

func (*Settings) MaxWindowSize

func (st *Settings) MaxWindowSize() uint32

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) Push

func (st *Settings) Push() bool

func (*Settings) Read

func (st *Settings) Read(d []byte)

Read reads from d and decodes the read values into st.

func (*Settings) Reset

func (st *Settings) Reset()

Reset resets settings to default values

func (*Settings) Serialize

func (st *Settings) Serialize(fr *FrameHeader)

func (*Settings) SetAck

func (st *Settings) SetAck(ack bool)

SetAck sets FlagAck when WriteTo is called.

func (*Settings) SetHeaderTableSize

func (st *Settings) SetHeaderTableSize(size uint32)

SetHeaderTableSize sets the maximum size of the header compression table used to decode header blocks.

Default value is 4096

func (*Settings) SetMaxConcurrentStreams

func (st *Settings) SetMaxConcurrentStreams(streams uint32)

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

func (st *Settings) SetMaxFrameSize(size uint32)

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

func (st *Settings) SetMaxHeaderListSize(size uint32)

SetMaxFrameSize sets maximum size of header list.

If this value is 0 indicates that there are no limit.

func (*Settings) SetMaxWindowSize

func (st *Settings) SetMaxWindowSize(size uint32)

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

func (st *Settings) SetPush(value bool)

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) Type

func (st *Settings) Type() FrameType

type Stream

type Stream struct {
	// contains filtered or unexported fields
}

func NewStream

func NewStream(id uint32, win int32) *Stream

func (*Stream) Ctx added in v0.1.0

func (s *Stream) Ctx() *fasthttp.RequestCtx

func (*Stream) ID

func (s *Stream) ID() uint32

func (*Stream) IncrWindow

func (s *Stream) IncrWindow(win int32)

func (*Stream) SetData

func (s *Stream) SetData(ctx *fasthttp.RequestCtx)

func (*Stream) SetID

func (s *Stream) SetID(id uint32)

func (*Stream) SetState

func (s *Stream) SetState(state StreamState)

func (*Stream) SetWindow

func (s *Stream) SetWindow(win int32)

func (*Stream) State

func (s *Stream) State() StreamState

func (*Stream) Window

func (s *Stream) Window() int32

type StreamState

type StreamState int8

StreamState ...

const (
	StreamStateIdle StreamState = iota
	StreamStateReserved
	StreamStateOpen
	StreamStateHalfClosed
	StreamStateClosed
)

func (StreamState) String

func (ss 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) CopyTo

func (wu *WindowUpdate) CopyTo(w *WindowUpdate)

CopyTo ...

func (*WindowUpdate) Deserialize

func (wu *WindowUpdate) Deserialize(fr *FrameHeader) error

func (*WindowUpdate) Increment

func (wu *WindowUpdate) Increment() int

Increment ...

func (*WindowUpdate) Reset

func (wu *WindowUpdate) Reset()

Reset ...

func (*WindowUpdate) Serialize

func (wu *WindowUpdate) Serialize(fr *FrameHeader)

func (*WindowUpdate) SetIncrement

func (wu *WindowUpdate) SetIncrement(increment int)

SetIncrement ...

func (*WindowUpdate) Type

func (wu *WindowUpdate) Type() FrameType

Directories

Path Synopsis
examples

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL