http2

package module
v0.0.0-...-7aa6403 Latest Latest
Warning

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

Go to latest
Published: Feb 13, 2021 License: Apache-2.0 Imports: 13 Imported by: 0

README

HTTP2

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

Example

package main

import (
	"fmt"
	"log"

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

func main() {
	cert, priv, err := GenerateTestCertificate("localhost:8080")
	if err != nil {
		log.Fatalln(err)
	}

	s := &fasthttp.Server{
		Handler: requestHandler,
		Name:    "http2 test",
	}
	err = s.AppendCertEmbed(cert, priv)
	if err != nil {
		log.Fatalln(err)
	}

	http2.ConfigureServer(s)

	err = s.ListenAndServeTLS(":8443", "", "")
	if err != nil {
		log.Fatalln(err)
	}
}

func requestHandler(ctx *fasthttp.RequestCtx) {
	fmt.Printf("%s\n", ctx.Request.Header.Header())
	if ctx.Request.Header.IsPost() {
		fmt.Fprintf(ctx, "%s\n", ctx.Request.Body())
	} else {
		fmt.Fprintf(ctx, "Hello 21th century!\n")
	}
}

Documentation

Index

Constants

View Source
const (
	// Error codes (http://httpwg.org/specs/rfc7540.html#ErrorCodes)
	//
	// Errors must be uint32 because of FrameReset
	NoError              uint32 = 0x0
	ProtocolError        uint32 = 0x1
	InternalError        uint32 = 0x2
	FlowControlError     uint32 = 0x3
	SettingsTimeoutError uint32 = 0x4
	StreamClosedError    uint32 = 0x5
	FrameSizeError       uint32 = 0x6
	RefusedStreamError   uint32 = 0x7
	CancelError          uint32 = 0x8
	CompressionError     uint32 = 0x9
	ConnectionError      uint32 = 0xa
	EnhanceYourCalm      uint32 = 0xb
	InadequateSecurity   uint32 = 0xc
	HTTP11Required       uint32 = 0xd
)
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"
)

Variables

View Source
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")
)

Functions

func Error

func Error(code uint32) error

Error returns error of uint32 declared error codes.

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 ReleaseContinuation

func ReleaseContinuation(c *Continuation)

ReleaseContinuation ...

func ReleaseData

func ReleaseData(data *Data)

ReleaseData ...

func ReleaseFrame

func ReleaseFrame(fr *Frame)

ReleaseFrame reset and puts fr to the pool.

func ReleaseGoAway

func ReleaseGoAway(ga *GoAway)

ReleaseGoAway ...

func ReleaseHPACK

func ReleaseHPACK(hpack *HPACK)

ReleaseHPACK puts HPACK to the pool

func ReleaseHeaderField

func ReleaseHeaderField(hf *HeaderField)

ReleaseHeaderField puts HeaderField to the pool.

func ReleaseHeaders

func ReleaseHeaders(h *Headers)

ReleaaseHeaders ...

func ReleasePing

func ReleasePing(pp *Ping)

ReleasePing ...

func ReleasePriority

func ReleasePriority(pry *Priority)

ReleasePriority retusn pry to the Priority frame pool.

func ReleasePushPromise

func ReleasePushPromise(pp *PushPromise)

ReleasePushPromise ...

func ReleaseRstStream

func ReleaseRstStream(rst *RstStream)

ReleaseRstStream ...

func ReleaseSettings

func ReleaseSettings(st *Settings)

ReleaseSettings puts st into settings pool to be reused in the future.

func ReleaseWindowUpdate

func ReleaseWindowUpdate(wu *WindowUpdate)

ReleaseWindowUpdate ...

func WritePreface

func WritePreface(wr io.Writer) error

WritePreface writes HTTP/2 preface to the wr.

Types

type Continuation

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

Continuation ...

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

func AcquireContinuation

func AcquireContinuation() *Continuation

AcquireContinuation ...

func (*Continuation) AppendHeader

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

AppendHeader ...

func (*Continuation) CopyTo

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

func (*Continuation) Header

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

Header returns Header bytes.

func (*Continuation) ReadFrame

func (c *Continuation) ReadFrame(fr *Frame) (err error)

ReadFrame reads decodes fr payload into c.

func (*Continuation) Reset

func (c *Continuation) Reset()

Reset ...

func (*Continuation) SetEndStream

func (c *Continuation) SetEndStream(value bool)

SetEndStream ...

func (*Continuation) SetHeader

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

SetHeader ...

func (*Continuation) Write

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

Write ...

func (*Continuation) WriteFrame

func (c *Continuation) WriteFrame(fr *Frame) error

WriteFrame ...

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 AcquireData

func AcquireData() (data *Data)

AcquireData ...

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

func (data *Data) Len() uint32

func (*Data) Padding

func (data *Data) Padding() bool

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

func (*Data) ReadFrame

func (data *Data) ReadFrame(fr *Frame) (err error)

ReadFrame reads data from fr.

This function does not reset the Frame.

func (*Data) Reset

func (data *Data) Reset()

Reset ...

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

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

Write writes b to data

func (*Data) WriteFrame

func (data *Data) WriteFrame(fr *Frame)

WriteFrame writes the data to the frame payload setting FlagPadded.

This function only resets the frame payload.

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 AcquireFrame

func AcquireFrame() *Frame

AcquireFrame gets a Frame from pool.

func (*Frame) AddFlag

func (fr *Frame) AddFlag(f FrameFlags)

AddFlag adds a flag to frame flags.

func (*Frame) AppendPayload

func (fr *Frame) AppendPayload(src []byte) (int, error)

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

func (fr *Frame) DelFlag(f FrameFlags)

DelFlag deletes f from frame flags

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

func (fr *Frame) Len() uint32

Len returns the payload length

func (*Frame) MaxLen

func (fr *Frame) MaxLen() uint32

MaxLen returns max negotiated payload length.

func (*Frame) Payload

func (fr *Frame) Payload() []byte

Payload returns processed payload deleting padding and additional headers.

func (*Frame) RawHeader

func (fr *Frame) RawHeader() []byte

RawHeader returns frame header bytes.

func (*Frame) ReadFrom

func (fr *Frame) ReadFrom(br io.Reader) (int64, error)

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

func (fr *Frame) ReadFromLimitPayload(br io.Reader, max uint32) (int64, error)

ReadFromLimitPayload reads frame from reader limiting the payload.

func (*Frame) Reset

func (fr *Frame) Reset()

Reset resets header values.

func (*Frame) SetMaxLen

func (fr *Frame) SetMaxLen(maxLen uint32)

SetMaxLen sets max payload length to read.

func (*Frame) SetPayload

func (fr *Frame) SetPayload(b []byte) (err error)

SetPayload sets new payload to fr

This function returns ErrPayloadExceeds if payload length exceeds negotiated maximum size.

func (*Frame) SetStream

func (fr *Frame) 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 (*Frame) SetType

func (fr *Frame) SetType(kind FrameType)

Setkind sets the frame type for the current frame.

func (*Frame) Stream

func (fr *Frame) Stream() uint32

Stream returns the stream id of the current frame.

func (*Frame) Type

func (fr *Frame) Type() FrameType

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

func (*Frame) Write

func (fr *Frame) Write(b []byte) (int, error)

Write writes b to frame payload.

If the result payload exceeds the max length ErrPayloadExceeds is returned. TODO: Add example of continuation frame

func (*Frame) WriteTo

func (fr *Frame) WriteTo(w io.Writer) (wb int64, err error)

WriteTo writes frame to the Writer.

This function returns Frame bytes written and/or error.

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 GoAway

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

GoAway ...

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

func AcquireGoAway

func AcquireGoAway() *GoAway

AcquireGoAway ...

func (*GoAway) Code

func (ga *GoAway) Code() uint32

Code ...

func (*GoAway) CopyTo

func (ga *GoAway) CopyTo(ga2 *GoAway)

CopyTo ...

func (*GoAway) Data

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

Data ...

func (*GoAway) ReadFrame

func (ga *GoAway) ReadFrame(fr *Frame) (err error)

ReadFrame ...

func (*GoAway) Reset

func (ga *GoAway) Reset()

Reset ...

func (*GoAway) SetCode

func (ga *GoAway) SetCode(code uint32)

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

func (ga *GoAway) WriteFrame(fr *Frame) (err error)

WriteFrame ...

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

func (hpack *HPACK) Add(key, value string)

Add adds the key and the value to the Header.

func (*HPACK) AddBytes

func (hpack *HPACK) AddBytes(key, value []byte)

....

func (*HPACK) AddBytesK

func (hpack *HPACK) AddBytesK(key []byte, value string)

...

func (*HPACK) AddBytesV

func (hpack *HPACK) AddBytesV(key string, value []byte)

...

func (*HPACK) AddField

func (hpack *HPACK) AddField(hf *HeaderField)

AddField appends the field to the header list.

func (*HPACK) AppendBytes

func (hpack *HPACK) AppendBytes(dst []byte) []byte

AppendBytes appends hpack headers to dst and returns the new dst.

func (*HPACK) AppendHeader

func (hpack *HPACK) AppendHeader(dst []byte, hf *HeaderField) []byte

AppendHeader writes hpack to dst returning the result byte slice.

func (*HPACK) DynamicSize

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

Dynamic size returns the size of the dynamic table. https://tools.ietf.org/html/rfc7541#section-4.1

func (*HPACK) MarshalTo

func (hpack *HPACK) MarshalTo(dst []byte) []byte

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

func (hpack *HPACK) Peek(key string) (value []byte)

Peek returns HeaderField value of the given key.

value will be nil if key is not found.

func (*HPACK) PeekBytes

func (hpack *HPACK) PeekBytes(key []byte) (value []byte)

PeekBytes returns HeaderField value of the given key in bytes.

value will be nil if key is not found.

func (*HPACK) PeekField

func (hpack *HPACK) PeekField(key string) (hf *HeaderField)

PeekField returns HeaderField structure of the given key.

hf will be nil in case key is not found.

func (*HPACK) PeekFieldBytes

func (hpack *HPACK) PeekFieldBytes(key []byte) (hf *HeaderField)

PeekFieldBytes returns HeaderField structure of the given key in bytes.

hf will be nil in case key is not found.

func (*HPACK) Range

func (hpack *HPACK) Range(fn func(*HeaderField))

func (*HPACK) Reset

func (hpack *HPACK) Reset()

Reset deletes and realeases all dynamic header fields

func (*HPACK) SetMaxTableSize

func (hpack *HPACK) SetMaxTableSize(size int)

SetMaxTableSize sets the maximum dynamic table size.

func (*HPACK) String

func (hpack *HPACK) String() string

String returns HPACK as a string like an HTTP/1.1 header.

type HTTP2ProtoError

type HTTP2ProtoError struct {
	Code   int
	Reason string
}

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

func AcquireHeaders() *Headers

AcquireHeaders ...

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

func (h *Headers) EndHeaders() bool

EndHeaders ...

func (*Headers) EndStream

func (h *Headers) EndStream() bool

EndStream ...

func (*Headers) Headers

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

RawHeaders ...

func (*Headers) Padding

func (h *Headers) Padding() bool

Padding ...

func (*Headers) ReadFrame

func (h *Headers) ReadFrame(fr *Frame) (err error)

ReadFrame reads header data from fr.

This function appends over rawHeaders .....

func (*Headers) Reset

func (h *Headers) Reset()

Reset ...

func (*Headers) SetEndHeaders

func (h *Headers) SetEndHeaders(value bool)

SetEndHeaders ...

func (*Headers) SetEndStream

func (h *Headers) SetEndStream(value bool)

SetEndHeaders ...

func (*Headers) SetHeaders

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

SetHeaders ...

func (*Headers) SetPadding

func (h *Headers) SetPadding(value bool)

SetPadding sets hasPaddingding value ...

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

func (h *Headers) Weight() byte

Weight ...

func (*Headers) WriteFrame

func (h *Headers) WriteFrame(fr *Frame) error

type Ping

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

Ping ...

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

func AcquirePing

func AcquirePing() *Ping

AcquirePing ...

func (*Ping) CopyTo

func (ping *Ping) CopyTo(p *Ping)

CopyTo ...

func (*Ping) ReadFrame

func (ping *Ping) ReadFrame(fr *Frame) error

ReadFrame ...

func (*Ping) Reset

func (ping *Ping) Reset()

Reset ...

func (*Ping) SetData

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

SetData ...

func (*Ping) Write

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

Write ...

func (*Ping) WriteFrame

func (ping *Ping) WriteFrame(fr *Frame) error

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

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

CopyTo ...

func (*Priority) ReadFrame

func (pry *Priority) ReadFrame(fr *Frame) (err error)

ReadFrame reads frame payload and decodes the values into pry.

func (*Priority) Reset

func (pry *Priority) Reset()

Resets resets priority fields.

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

func (pry *Priority) Weight() byte

Weight returns the Priority frame weight.

func (*Priority) WriteFrame

func (pry *Priority) WriteFrame(fr *Frame)

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 AcquirePushPromise

func AcquirePushPromise() *PushPromise

AcquirePushPromise ...

func (*PushPromise) ReadFrame

func (pp *PushPromise) ReadFrame(fr *Frame) (err error)

ReadFrame ...

func (*PushPromise) Reset

func (pp *PushPromise) Reset()

Reset ...

func (*PushPromise) SetHeader

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

func (*PushPromise) Write

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

func (*PushPromise) WriteFrame

func (pp *PushPromise) WriteFrame(fr *Frame) (err error)

WriteFrame ...

type RstStream

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

RstStream ...

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

func AcquireRstStream

func AcquireRstStream() *RstStream

AcquireRstStream ...

func (*RstStream) Code

func (rst *RstStream) Code() uint32

Code ...

func (*RstStream) CopyTo

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

CopyTo ...

func (*RstStream) Error

func (rst *RstStream) Error() error

Error ...

func (*RstStream) ReadFrame

func (rst *RstStream) ReadFrame(fr *Frame) error

ReadFrame ...

func (*RstStream) Reset

func (rst *RstStream) Reset()

Reset ...

func (*RstStream) SetCode

func (rst *RstStream) SetCode(code uint32)

SetCode ...

func (*RstStream) WriteFrame

func (rst *RstStream) WriteFrame(fr *Frame)

WriteFrame ...

type Server

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

Server ...

func ConfigureServer

func ConfigureServer(s *fasthttp.Server) *Server

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.

func (*Server) Handle

func (s *Server) Handle(ctx *connCtx, strm *Stream) (err 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 AcquireSettings

func AcquireSettings() *Settings

AcquireSettings gets a Settings object from the pool with default values.

func (*Settings) Clear

func (st *Settings) Clear()

func (*Settings) CopyTo

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

CopyTo copies st fields to st2

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

func (st *Settings) ReadFrame(fr *Frame) error

ReadFrame reads and decodes frame payload into st values

func (*Settings) Reset

func (st *Settings) Reset()

Reset resets settings to default values

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

func (st *Settings) WriteFrame(fr *Frame) error

WriteFrame writes the settings frame into the frame payload

type Stream

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

func (*Stream) IsClosed

func (strm *Stream) IsClosed() bool

func (*Stream) State

func (strm *Stream) State() StreamState

type StreamState

type StreamState int8
const (
	StateIdle StreamState = iota
	StateReserved
	StateOpen
	StateHalfClosed
	StateClosed
)

type WindowUpdate

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

WindowUpdate ...

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

func AcquireWindowUpdate

func AcquireWindowUpdate() *WindowUpdate

AcquireWindowUpdate ...

func (*WindowUpdate) CopyTo

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

CopyTo ...

func (*WindowUpdate) Increment

func (wu *WindowUpdate) Increment() uint32

Increment ...

func (*WindowUpdate) ReadFrame

func (wu *WindowUpdate) ReadFrame(fr *Frame) (err error)

ReadFrame ...

func (*WindowUpdate) Reset

func (wu *WindowUpdate) Reset()

Reset ...

func (*WindowUpdate) SetIncrement

func (wu *WindowUpdate) SetIncrement(increment uint32)

SetIncrement ...

func (*WindowUpdate) WriteFrame

func (wu *WindowUpdate) WriteFrame(fr *Frame)

WriteFrame ...

Directories

Path Synopsis
examples

Jump to

Keyboard shortcuts

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