Documentation
¶
Index ¶
- Variables
- func Connect(url string) (net.Conn, error)
- func ConnectTLS(url string, tlsConfig *tls.Config) (net.Conn, error)
- func HandleNetworkError(stream *Stream, err error)
- func Listen(ln net.Listener, director Director) error
- func NormalizeNetworkError(err error) error
- func ReadConfig(input interface{}, config interface{}) error
- func ReleaseStream(stream *Stream)
- func RespondWithError(stream *Stream, cause error, status int) error
- func SetLogger(logger log.Logger)
- type Connection
- type ConnectionAcceptor
- type ConnectionAcceptors
- type DataReceiver
- type DataSender
- type Director
- type ErrSmallBuffer
- type ErrorResponse
- type H1Upstream
- func (u *H1Upstream) Address() string
- func (u *H1Upstream) CancelStream(stream *Stream)
- func (u *H1Upstream) IsServed() bool
- func (u *H1Upstream) RetryStream(stream *Stream)
- func (u *H1Upstream) SendConnectionError(stream *Stream, lastStreamID uint32, errorCode frames.ErrorCode) error
- func (u *H1Upstream) SendData(stream *Stream, data []byte, endStream bool) error
- func (u *H1Upstream) SendHeaders(stream *Stream, params *HeadersParams, endStream bool) error
- func (u *H1Upstream) SendPushPromise(stream *Stream, headers Headers, promisedStreamID uint32) error
- func (u *H1Upstream) SendStreamError(stream *Stream, errorCode frames.ErrorCode) error
- func (u *H1Upstream) SendWindowUpdate(streamID uint32, windowSizeIncrement uint32) error
- func (u *H1Upstream) Serve() error
- func (u *H1Upstream) StreamCount() int
- type H2Upstream
- func (u *H2Upstream) Address() string
- func (u *H2Upstream) CancelStream(stream *Stream)
- func (u *H2Upstream) IsServed() bool
- func (u *H2Upstream) RetryStream(stream *Stream)
- func (u *H2Upstream) SendConnectionError(stream *Stream, lastStreamID uint32, errorCode frames.ErrorCode) error
- func (u *H2Upstream) SendData(stream *Stream, data []byte, endStream bool) error
- func (u *H2Upstream) SendHeaders(stream *Stream, params *HeadersParams, endStream bool) error
- func (u *H2Upstream) SendPushPromise(stream *Stream, headers Headers, promisedStreamID uint32) error
- func (u *H2Upstream) SendStreamError(stream *Stream, errorCode frames.ErrorCode) error
- func (u *H2Upstream) SendWindowUpdate(streamID uint32, windowSizeIncrement uint32) error
- func (u *H2Upstream) Serve() error
- func (u *H2Upstream) StreamCount() int
- type HTTPConnection
- func (c *HTTPConnection) Close() error
- func (c *HTTPConnection) DirectStream(stream *Stream, headers Headers) bool
- func (c *HTTPConnection) GetStream(streamID uint32) (*Stream, bool)
- func (c *HTTPConnection) LocalAddr() string
- func (c *HTTPConnection) NewStream(streamID uint32) *Stream
- func (c *HTTPConnection) RemoteAddr() string
- func (c *HTTPConnection) SendConnectionError(stream *Stream, lastStreamID uint32, errorCode frames.ErrorCode) error
- func (c *HTTPConnection) SendData(stream *Stream, data []byte, endStream bool) error
- func (c *HTTPConnection) SendHeaders(stream *Stream, params *HeadersParams, endStream bool) error
- func (c *HTTPConnection) SendPushPromise(stream *Stream, headers Headers, promisedStreamID uint32) error
- func (c *HTTPConnection) SendSettings(ack bool, settings map[frames.Setting]uint32) error
- func (c *HTTPConnection) SendStreamError(stream *Stream, errorCode frames.ErrorCode) error
- func (c *HTTPConnection) SendWindowUpdate(stream *Stream, windowSizeIncrement uint32) error
- func (c *HTTPConnection) Serve() error
- type Headers
- type HeadersParams
- type HeadersReceiver
- type HeadersSender
- type Middleware
- type MiddlewareLoader
- type NamedConnectionAcceptor
- type NamedUpstreamDialer
- type RDContext
- type RHContext
- type RequestHeader
- func (h *RequestHeader) IsDelete() bool
- func (h *RequestHeader) IsGet() bool
- func (h *RequestHeader) IsHTTP11() bool
- func (h *RequestHeader) IsHead() bool
- func (h *RequestHeader) IsPost() bool
- func (h *RequestHeader) IsPut() bool
- func (h *RequestHeader) Method() []byte
- func (h *RequestHeader) Read(r *bufio.Reader) error
- type SDContext
- type SHContext
- type Stream
- type StreamClosed
- type StreamState
- type Target
- type Upstream
- type UpstreamDialer
- type UpstreamDialers
Constants ¶
This section is empty.
Variables ¶
var ( // ErrUnknownHost denotes that the host could not be resolved. ErrUnknownHost = errors.New("unknown host") // ErrConnectionRefused denotes that the server refused the connection. ErrConnectionRefused = errors.New("connection refused") // ErrConnectionTimeout denotes that the server did not accept the connection before the timeout elapsed. ErrConnectionTimeout = errors.New("connection timeout") )
var ( // ErrNotFound denotes that a route for a given request path was not found. ErrNotFound = errors.New("route not found") ErrInternalServerError = errors.New("internal server error") ErrGatewayTimeout = errors.New("gateway timeout") )
var DefaultConnectionAcceptors = ConnectionAcceptors{ { Name: "HTTP", Accept: NewHTTPConnection, }, }
var DefaultUpstreamDialers = UpstreamDialers{ { Name: "HTTP/2", Dial: NewH2Upstream, }, { Name: "HTTP/1", Dial: NewH1Upstream, }, }
var ErrBodyTooLarge = errors.New("body size exceeds the given limit")
ErrBodyTooLarge is returned if either request or response body exceeds the given limit.
Functions ¶
func HandleNetworkError ¶
HandleNetworkError responses with the appropriate error depending on the error type.
func NormalizeNetworkError ¶
NormalizeNetworkError converts various network errors into easier to handle error variables.
func ReadConfig ¶
func ReadConfig(input interface{}, config interface{}) error
ReadConfig reads the configuration into a struct assuming the struct has the proper tags.
func ReleaseStream ¶
func ReleaseStream(stream *Stream)
Types ¶
type Connection ¶
type Connection interface {
io.Closer
Serve() error
GetStream(streamID uint32) (*Stream, bool)
DirectStream(stream *Stream, headers Headers) bool
// Stream creation
SendHeaders(stream *Stream, params *HeadersParams, endStream bool) error
SendPushPromise(stream *Stream, headers Headers, promisedStreamID uint32) error
// Sending data
SendData(stream *Stream, data []byte, endStream bool) error
SendWindowUpdate(stream *Stream, windowSizeIncrement uint32) error
// Error handling
SendStreamError(stream *Stream, errorCode frames.ErrorCode) error
SendConnectionError(stream *Stream, lastStreamID uint32, errorCode frames.ErrorCode) error
LocalAddr() string
RemoteAddr() string
}
func NewHTTPConnection ¶
func NewHTTPConnection(conn net.Conn, director Director) (Connection, error)
type ConnectionAcceptor ¶
type ConnectionAcceptor func(conn net.Conn, director Director) (Connection, error)
type ConnectionAcceptors ¶
type ConnectionAcceptors []NamedConnectionAcceptor
ConnectionAcceptors is a collection of NamedConnection that allows for lookup via `ForName`.
func (ConnectionAcceptors) ForName ¶
func (c ConnectionAcceptors) ForName(name string) (factory ConnectionAcceptor, ok bool)
ForName returns a `ConnectionFactory` and `ok` as true given a name if the connection factory is registered.
type DataReceiver ¶
type DataReceiver interface {
Middleware
ReceiveData(ctx *RDContext, data []byte, endStream bool) error
}
type DataSender ¶
type DataSender interface {
Middleware
SendData(ctx *SDContext, data []byte, endStream bool) error
}
type ErrSmallBuffer ¶
type ErrSmallBuffer struct {
// contains filtered or unexported fields
}
ErrSmallBuffer is returned when the provided buffer size is too small for reading request and/or response headers.
ReadBufferSize value from Server or clients should reduce the number of such errors.
type ErrorResponse ¶
type H1Upstream ¶
type H1Upstream struct {
// contains filtered or unexported fields
}
func (*H1Upstream) Address ¶
func (u *H1Upstream) Address() string
func (*H1Upstream) CancelStream ¶
func (u *H1Upstream) CancelStream(stream *Stream)
func (*H1Upstream) IsServed ¶
func (u *H1Upstream) IsServed() bool
func (*H1Upstream) RetryStream ¶
func (u *H1Upstream) RetryStream(stream *Stream)
func (*H1Upstream) SendConnectionError ¶
func (*H1Upstream) SendData ¶
func (u *H1Upstream) SendData(stream *Stream, data []byte, endStream bool) error
func (*H1Upstream) SendHeaders ¶
func (u *H1Upstream) SendHeaders(stream *Stream, params *HeadersParams, endStream bool) error
func (*H1Upstream) SendPushPromise ¶
func (u *H1Upstream) SendPushPromise(stream *Stream, headers Headers, promisedStreamID uint32) error
func (*H1Upstream) SendStreamError ¶
func (u *H1Upstream) SendStreamError(stream *Stream, errorCode frames.ErrorCode) error
func (*H1Upstream) SendWindowUpdate ¶
func (u *H1Upstream) SendWindowUpdate(streamID uint32, windowSizeIncrement uint32) error
func (*H1Upstream) Serve ¶
func (u *H1Upstream) Serve() error
func (*H1Upstream) StreamCount ¶
func (u *H1Upstream) StreamCount() int
type H2Upstream ¶
type H2Upstream struct {
// contains filtered or unexported fields
}
func (*H2Upstream) Address ¶
func (u *H2Upstream) Address() string
func (*H2Upstream) CancelStream ¶
func (u *H2Upstream) CancelStream(stream *Stream)
func (*H2Upstream) IsServed ¶
func (u *H2Upstream) IsServed() bool
func (*H2Upstream) RetryStream ¶
func (u *H2Upstream) RetryStream(stream *Stream)
func (*H2Upstream) SendConnectionError ¶
func (*H2Upstream) SendData ¶
func (u *H2Upstream) SendData(stream *Stream, data []byte, endStream bool) error
func (*H2Upstream) SendHeaders ¶
func (u *H2Upstream) SendHeaders(stream *Stream, params *HeadersParams, endStream bool) error
func (*H2Upstream) SendPushPromise ¶
func (u *H2Upstream) SendPushPromise(stream *Stream, headers Headers, promisedStreamID uint32) error
func (*H2Upstream) SendStreamError ¶
func (u *H2Upstream) SendStreamError(stream *Stream, errorCode frames.ErrorCode) error
func (*H2Upstream) SendWindowUpdate ¶
func (u *H2Upstream) SendWindowUpdate(streamID uint32, windowSizeIncrement uint32) error
func (*H2Upstream) Serve ¶
func (u *H2Upstream) Serve() error
func (*H2Upstream) StreamCount ¶
func (u *H2Upstream) StreamCount() int
type HTTPConnection ¶
type HTTPConnection struct {
// contains filtered or unexported fields
}
func (*HTTPConnection) Close ¶
func (c *HTTPConnection) Close() error
func (*HTTPConnection) DirectStream ¶
func (c *HTTPConnection) DirectStream(stream *Stream, headers Headers) bool
func (*HTTPConnection) GetStream ¶
func (c *HTTPConnection) GetStream(streamID uint32) (*Stream, bool)
func (*HTTPConnection) LocalAddr ¶
func (c *HTTPConnection) LocalAddr() string
func (*HTTPConnection) NewStream ¶
func (c *HTTPConnection) NewStream(streamID uint32) *Stream
func (*HTTPConnection) RemoteAddr ¶
func (c *HTTPConnection) RemoteAddr() string
func (*HTTPConnection) SendConnectionError ¶
func (*HTTPConnection) SendData ¶
func (c *HTTPConnection) SendData(stream *Stream, data []byte, endStream bool) error
func (*HTTPConnection) SendHeaders ¶
func (c *HTTPConnection) SendHeaders(stream *Stream, params *HeadersParams, endStream bool) error
func (*HTTPConnection) SendPushPromise ¶
func (c *HTTPConnection) SendPushPromise(stream *Stream, headers Headers, promisedStreamID uint32) error
func (*HTTPConnection) SendSettings ¶
func (*HTTPConnection) SendStreamError ¶
func (c *HTTPConnection) SendStreamError(stream *Stream, errorCode frames.ErrorCode) error
func (*HTTPConnection) SendWindowUpdate ¶
func (c *HTTPConnection) SendWindowUpdate(stream *Stream, windowSizeIncrement uint32) error
func (*HTTPConnection) Serve ¶
func (c *HTTPConnection) Serve() error
type Headers ¶
type Headers []hpack.HeaderField
type HeadersParams ¶
type HeadersParams struct {
Headers Headers
Priority bool
Exclusive bool
StreamDependencyID uint32
Weight uint8
}
func (*HeadersParams) Add ¶
func (h *HeadersParams) Add(name, value string)
func (*HeadersParams) AsMap ¶
func (h *HeadersParams) AsMap() url.Values
func (*HeadersParams) ByName ¶
func (h *HeadersParams) ByName(name string) string
func (*HeadersParams) Set ¶
func (h *HeadersParams) Set(name, value string)
type HeadersReceiver ¶
type HeadersReceiver interface {
Middleware
ReceiveHeaders(ctx *RHContext, params *HeadersParams, endStream bool) error
}
type HeadersSender ¶
type HeadersSender interface {
Middleware
SendHeaders(ctx *SHContext, params *HeadersParams, endStream bool) error
}
type Middleware ¶
type Middleware interface {
Name() string
InitialState() interface{}
}
type MiddlewareLoader ¶
type MiddlewareLoader func(input interface{}) (Middleware, error)
type NamedConnectionAcceptor ¶
type NamedConnectionAcceptor struct {
Name string
Accept ConnectionAcceptor
}
NamedConnectionAcceptor associates a name with a connection factory.
type NamedUpstreamDialer ¶
type NamedUpstreamDialer struct {
Name string
Dial UpstreamDialer
}
type RDContext ¶
type RDContext struct {
*Stream
// contains filtered or unexported fields
}
RDContext is the context for receiving data.
type RHContext ¶
type RHContext struct {
*Stream
// contains filtered or unexported fields
}
RHContext is the context for receiving headers.
type RequestHeader ¶
type RequestHeader struct {
// contains filtered or unexported fields
}
func (*RequestHeader) IsDelete ¶
func (h *RequestHeader) IsDelete() bool
IsDelete returns true if request method is DELETE.
func (*RequestHeader) IsGet ¶
func (h *RequestHeader) IsGet() bool
IsGet returns true if request method is GET.
func (*RequestHeader) IsHTTP11 ¶
func (h *RequestHeader) IsHTTP11() bool
IsHTTP11 returns true if the request is HTTP/1.1.
func (*RequestHeader) IsHead ¶
func (h *RequestHeader) IsHead() bool
IsHead returns true if request method is HEAD.
func (*RequestHeader) IsPost ¶
func (h *RequestHeader) IsPost() bool
IsPost returns true if request methos is POST.
func (*RequestHeader) IsPut ¶
func (h *RequestHeader) IsPut() bool
IsPut returns true if request method is PUT.
func (*RequestHeader) Method ¶
func (h *RequestHeader) Method() []byte
Method returns HTTP request method.
type SDContext ¶
type SDContext struct {
*Stream
// contains filtered or unexported fields
}
SDContext is the context for sending data.
type SHContext ¶
type SHContext struct {
*Stream
// contains filtered or unexported fields
}
SHContext is the context for sending headers.
type Stream ¶
type Stream struct {
LocalID uint32
RemoteID uint32
Connection Connection
Upstream Upstream
Info interface{}
// contains filtered or unexported fields
}
func AcquireStream ¶
func AcquireStream() *Stream
func (*Stream) AddCloseCallback ¶
func (s *Stream) AddCloseCallback(callback StreamClosed)
func (*Stream) CloseLocal ¶
func (s *Stream) CloseLocal()
func (*Stream) CloseRemote ¶
func (s *Stream) CloseRemote()
func (*Stream) Initialize ¶
func (s *Stream) Initialize(middlewares ...Middleware)
type StreamClosed ¶
type StreamClosed func(stream *Stream)
type StreamState ¶
type StreamState int32
const ( StreamStateIdle StreamState = iota StreamStateOpen StreamStateClosed )
type Target ¶
type Target struct {
Upstream Upstream
Middlewares []Middleware
Info interface{}
}
type Upstream ¶
type Upstream interface {
IsServed() bool
Serve() error
StreamCount() int
// Stream creation
SendHeaders(stream *Stream, params *HeadersParams, endStream bool) error
SendPushPromise(stream *Stream, headers Headers, promisedStreamID uint32) error
// Sending data
SendData(stream *Stream, data []byte, endStream bool) error
SendWindowUpdate(streamID uint32, windowSizeIncrement uint32) error
// Error handling
SendStreamError(stream *Stream, errorCode frames.ErrorCode) error
SendConnectionError(stream *Stream, lastStreamID uint32, errorCode frames.ErrorCode) error
CancelStream(stream *Stream)
RetryStream(stream *Stream)
Address() string
}
type UpstreamDialers ¶
type UpstreamDialers []NamedUpstreamDialer
func (UpstreamDialers) ForName ¶
func (u UpstreamDialers) ForName(name string) (dialer UpstreamDialer, ok bool)