Documentation ¶
Overview ¶
Package http2stream provides an implementation of an HTTP/2 server and client that allows piping streams (useful for creating proxies).
Index ¶
- Constants
- type FilterFun
- type HTTP2Client
- type HTTP2Server
- type HTTP2Stream
- func (stream *HTTP2Stream) Closed() <-chan struct{}
- func (stream *HTTP2Stream) GetHeaders() map[string][]string
- func (stream *HTTP2Stream) GetReceiveBuffer() *leverutil.UnboundedChannel
- func (stream *HTTP2Stream) ProxyTo(destStream *HTTP2Stream, filterTo FilterFun, filterFrom FilterFun)
- func (stream *HTTP2Stream) Write(item MsgItem)
- type MsgBytes
- type MsgEOF
- type MsgError
- type MsgHeaders
- type MsgItem
- type StreamHandler
Constants ¶
const PackageName = "http2stream"
PackageName is the name of this package.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type HTTP2Client ¶
type HTTP2Client struct {
// contains filtered or unexported fields
}
HTTP2Client represents a collection of client HTTP2 connections. The structure manages a connection pool internally.
func NewHTTP2Client ¶
func NewHTTP2Client( connectionConnectTimeout time.Duration, connectionExpiry time.Duration) (*HTTP2Client, error)
NewHTTP2Client creates a new HTTP2Client.
func (*HTTP2Client) KeepAlive ¶
func (client *HTTP2Client) KeepAlive(addr string)
KeepAlive resets the connection to addr's expiry.
func (*HTTP2Client) NewStream ¶
func (client *HTTP2Client) NewStream(addr string) (*HTTP2Stream, error)
NewStream creates a new HTTP2 stream to the provided server address. Also creates the underlying HTTP2 connection if it doesn't already exist.
type HTTP2Server ¶
type HTTP2Server struct {
// contains filtered or unexported fields
}
HTTP2Server represents a HTTP2 server which listens for connections.
func NewHTTP2Server ¶
func NewHTTP2Server() *HTTP2Server
NewHTTP2Server returns a new instance of HTTP2Server.
func (*HTTP2Server) Serve ¶
func (server *HTTP2Server) Serve( protocol string, listenAddr string, streamHandler StreamHandler) (net.Listener, chan struct{}, error)
Serve listens for connections on provided address.
func (*HTTP2Server) Stop ¶
func (server *HTTP2Server) Stop()
Stop causes the server to close all open connections and exit any serving loops.
type HTTP2Stream ¶
type HTTP2Stream struct {
// contains filtered or unexported fields
}
HTTP2Stream represents a HTTP2Stream connected to an endpoint (either client or server).
func (*HTTP2Stream) Closed ¶
func (stream *HTTP2Stream) Closed() <-chan struct{}
Closed returns a channel that is closed when the stream is closed.
func (*HTTP2Stream) GetHeaders ¶
func (stream *HTTP2Stream) GetHeaders() map[string][]string
GetHeaders returns the headers received from the client. These are available only to server streams.
func (*HTTP2Stream) GetReceiveBuffer ¶
func (stream *HTTP2Stream) GetReceiveBuffer() *leverutil.UnboundedChannel
GetReceiveBuffer returns the buffer of MsgItem's that can be consumed by a user application to handle messages from the stream.
func (*HTTP2Stream) ProxyTo ¶
func (stream *HTTP2Stream) ProxyTo( destStream *HTTP2Stream, filterTo FilterFun, filterFrom FilterFun)
ProxyTo causes the current stream to be proxied to provided destStream.
func (*HTTP2Stream) Write ¶
func (stream *HTTP2Stream) Write(item MsgItem)
Write can be used to send messages on the wire.
type MsgBytes ¶
type MsgBytes struct { Data []byte EndStream bool // AfterRead needs to be called after the data has been consumed, to signal // the peer that it's ok to send more (flow control update window). AfterRead func() }
MsgBytes represents a chunk of data sent / received by a HTTP2Stream on the wire.
type MsgEOF ¶
type MsgEOF struct { }
MsgEOF represents the end data sent / received by a HTTP2Stream on the wire.
type MsgError ¶
type MsgError struct {
Err error
}
MsgError represents a transport error of a HTTP2Stream.
type MsgHeaders ¶
MsgHeaders represents headers sent / received in a HTTP2Stream. Note: This may appear multiple times on a stream.
type MsgItem ¶
type MsgItem interface {
// contains filtered or unexported methods
}
MsgItem is a message sent / received from a stream (bytes, headers, errors or EOF).
type StreamHandler ¶
type StreamHandler func(stream *HTTP2Stream)
StreamHandler is a function that handles incoming streams.