Documentation
¶
Overview ¶
tinywss
A module for establishing a rudimentary secure "websocket". Performs websocket handshake, but does not actually enforce the websocket protocol for data exchanged afterwards. Exposes a dialer and listener returning objects conforming to net.Conn and net.Listener.
It is not meant to be compatible with anything but itself.
Index ¶
Constants ¶
const ( // ProtocolRaw specifies a raw (not multiplexed) connection ProtocolRaw = "tinywss-raw" // ProtocolMux specifies a multiplexed connection ProtocolMux = "tinywss-smux" )
Variables ¶
var ( // ErrListenerClosed is the error returned if listener is used after closed ErrListenerClosed = errors.New("listener closed") // ErrDialerClosed is the error returned if client is used after closed ErrClientClosed = errors.New("client closed") )
Functions ¶
func ListenAddr ¶
func ListenAddr(opts *ListenOpts) (net.Listener, error)
ListenAddr starts a tinywss server listening at the configured address.
func NewRoundTripper ¶
func NewRoundTripper(dial DialFN) *roundTripHijacker
creates a new default RoundTripHijacker
Types ¶
type Client ¶
type Client interface {
// DialContext attempts to dial the configured server, returning an error if
// the context given expires before the server can be contacted.
DialContext(ctx context.Context) (net.Conn, error)
// Close shuts down any resources associated with the client
Close() error
}
func NewClient ¶
func NewClient(opts *ClientOpts) Client
NewClient constructs a new tinywss.Client with the specified options
type ClientOpts ¶
type ClientOpts struct {
URL string
MaxPendingDials int64
RoundTrip RoundTripHijacker
Headers http.Header
// Multiplex Options
Multiplexed bool
KeepAliveInterval time.Duration
KeepAliveTimeout time.Duration
MaxFrameSize int
MaxReceiveBuffer int
}
ClientOpts contains configuration options for NewClient
type HandshakeError ¶
type HandshakeError struct {
// contains filtered or unexported fields
}
HandshakeError is returned when handshake expectations fail
func (HandshakeError) Error ¶
func (e HandshakeError) Error() string
type ListenOpts ¶
type ListenOpts struct {
Addr string
CertFile string
KeyFile string
TLSConf *tls.Config
HandshakeTimeout time.Duration
Protocols []string // allowed protocols
// If provided, this listener is used instead of starting
// a TLS listener using the tls configuration specified.
// Addr, CertFile, KeyFile and TLSConf are ignored if this
// is given.
Listener net.Listener
// Multiplex options
KeepAliveInterval time.Duration
KeepAliveTimeout time.Duration
MaxFrameSize int
MaxReceiveBuffer int
}
Configuration options for ListenAddr
type RoundTripHijacker ¶
type RoundTripHijacker interface {
RoundTripHijack(*http.Request) (*http.Response, net.Conn, error)
}
RoundTripHijacker is the interface used by the Client to make the HTTP upgrade request and hijack the the underlying connection.
type WsConn ¶
func (*WsConn) UpgradeHeaders ¶
returns the headers on the initial HTTP connection that was upgraded to create this WsConn.