wsstream

package
v0.0.0-...-34322f7 Latest Latest
Warning

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

Go to latest
Published: Aug 4, 2017 License: Apache-2.0, Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package wsstream contains utilities for streaming content over WebSockets. The Conn type allows callers to multiplex multiple read/write channels over a single websocket. The Reader type allows an io.Reader to be copied over a websocket channel as binary content.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsWebSocketRequest

func IsWebSocketRequest(req *http.Request) bool

IsWebSocketRequest returns true if the incoming request contains connection upgrade headers for WebSockets.

Types

type ChannelType

type ChannelType int
const (
	IgnoreChannel ChannelType = iota
	ReadChannel
	WriteChannel
	ReadWriteChannel
)

type Conn

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

Conn supports sending multiple binary channels over a websocket connection. Supports only the "channel.k8s.io" subprotocol.

func NewConn

func NewConn(channels ...ChannelType) *Conn

NewConn creates a WebSocket connection that supports a set of channels. Channels begin each web socket message with a single byte indicating the channel number (0-N). 255 is reserved for future use. The channel types for each channel are passed as an array, supporting the different duplex modes. Read and Write refer to whether the channel can be used as a Reader or Writer.

func (*Conn) Close

func (conn *Conn) Close() error

Close is only valid after Open has been called

func (*Conn) Open

func (conn *Conn) Open(w http.ResponseWriter, req *http.Request) ([]io.ReadWriteCloser, error)

Open the connection and create channels for reading and writing.

func (*Conn) SetIdleTimeout

func (conn *Conn) SetIdleTimeout(duration time.Duration)

SetIdleTimeout sets the interval for both reads and writes before timeout. If not specified, there is no timeout on the connection.

type Reader

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

Reader supports returning an arbitrary byte stream over a websocket channel. Supports the "binary.k8s.io" and "base64.binary.k8s.io" subprotocols.

func NewReader

func NewReader(r io.Reader, ping bool) *Reader

NewReader creates a WebSocket pipe that will copy the contents of r to a provided WebSocket connection. If ping is true, a zero length message will be sent to the client before the stream begins reading.

func (*Reader) Copy

func (r *Reader) Copy(w http.ResponseWriter, req *http.Request) error

Copy the reader to the response. The created WebSocket is closed after this method completes.

func (*Reader) SetIdleTimeout

func (r *Reader) SetIdleTimeout(duration time.Duration)

SetIdleTimeout sets the interval for both reads and writes before timeout. If not specified, there is no timeout on the reader.

Jump to

Keyboard shortcuts

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