proxy

package
v0.0.0-...-9596210 Latest Latest
Warning

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

Go to latest
Published: Oct 15, 2018 License: MIT Imports: 25 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
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")
)
View Source
var (
	// ErrNotFound denotes that a route for a given request path was not found.
	ErrNotFound            = errors.New("route not found")
	ErrServiceUnavailable  = errors.New("service unavailable")
	ErrInternalServerError = errors.New("internal server error")
	ErrGatewayTimeout      = errors.New("gateway timeout")
)
View Source
var DefaultConnectionAcceptors = ConnectionAcceptors{
	{
		Name:   "HTTP",
		Accept: NewHTTPConnection,
	},
}
View Source
var DefaultUpstreamDialers = UpstreamDialers{
	{
		Name: "HTTP/2",
		Dial: NewH2Upstream,
	},
	{
		Name: "HTTP/1",
		Dial: NewH1Upstream,
	},
}
View Source
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 Connect

func Connect(url string) (net.Conn, error)

func ConnectTLS

func ConnectTLS(url string, tlsConfig *tls.Config) (net.Conn, error)

func HandleNetworkError

func HandleNetworkError(stream *Stream, err error)

HandleNetworkError responses with the appropriate error depending on the error type.

func Listen

func Listen(ln net.Listener, director Director) error

func NormalizeNetworkError

func NormalizeNetworkError(err error) error

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)

func RespondWithError

func RespondWithError(stream *Stream, cause error, status int) error

func SetLogger

func SetLogger(logger log.Logger)

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 Accept

func Accept(ln net.Listener, director Director) (Connection, error)

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 Director

type Director func(remoteAddr net.Addr, headers Headers) (Target, 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 ErrorResponse struct {
	Status  int    `json:"status"`
	Message string `json:"message"`
}

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 (u *H1Upstream) SendConnectionError(stream *Stream, lastStreamID uint32, errorCode frames.ErrorCode) error

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 (u *H2Upstream) SendConnectionError(stream *Stream, lastStreamID uint32, errorCode frames.ErrorCode) error

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 (c *HTTPConnection) SendConnectionError(stream *Stream, lastStreamID uint32, errorCode frames.ErrorCode) error

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 (c *HTTPConnection) SendSettings(ack bool, settings map[frames.Setting]uint32) error

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

func (*Headers) Add

func (h *Headers) Add(name, value string)

func (Headers) ByName

func (h Headers) ByName(name string) string

func (*Headers) Set

func (h *Headers) Set(name, value string)

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.

func (*RDContext) Next

func (c *RDContext) Next(data []byte, endStream bool) error

Next handles invoking the next `ReceiveData` middleware.

type RHContext

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

RHContext is the context for receiving headers.

func (*RHContext) Next

func (c *RHContext) Next(params *HeadersParams, endStream bool) error

Next handles invoking the next `ReceiveHeaders` middleware.

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.

func (*RequestHeader) Read

func (h *RequestHeader) Read(r *bufio.Reader) error

Read reads request header from r.

io.EOF is returned if r is closed before reading the first header byte.

type SDContext

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

SDContext is the context for sending data.

func (*SDContext) Next

func (c *SDContext) Next(data []byte, endStream bool) error

Next handles invoking the next `SendData` middleware.

type SHContext

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

SHContext is the context for sending headers.

func (*SHContext) Next

func (c *SHContext) Next(params *HeadersParams, endStream bool) error

Next handles invoking the next `SendHeaders` middleware.

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

func (s *Stream) FullClose()

func (*Stream) Initialize

func (s *Stream) Initialize(middlewares ...Middleware)

func (*Stream) State

func (s *Stream) State() interface{}

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
}

func NewH1Upstream

func NewH1Upstream(url string, tlsConfig *tls.Config) (Upstream, error)

func NewH2Upstream

func NewH2Upstream(url string, tlsConfig *tls.Config) (Upstream, error)

type UpstreamDialer

type UpstreamDialer func(url string, tlsConfig *tls.Config) (Upstream, error)

type UpstreamDialers

type UpstreamDialers []NamedUpstreamDialer

func (UpstreamDialers) ForName

func (u UpstreamDialers) ForName(name string) (dialer UpstreamDialer, ok bool)

Jump to

Keyboard shortcuts

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