common

package
v0.0.0-...-b5edf18 Latest Latest
Warning

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

Go to latest
Published: Feb 17, 2016 License: BSD-2-Clause Imports: 18 Imported by: 0

Documentation

Overview

Package common contains shared functionality for the spdy package.

Index

Constants

View Source
const (
	SYN_STREAMv2    = 1
	SYN_REPLYv2     = 2
	RST_STREAMv2    = 3
	SETTINGSv2      = 4
	NOOPv2          = 5
	PINGv2          = 6
	GOAWAYv2        = 7
	HEADERSv2       = 8
	WINDOW_UPDATEv2 = 9
	CONTROL_FRAMEv2 = -1
	DATA_FRAMEv2    = -2
)

Frame types in SPDY/2

View Source
const (
	SYN_STREAMv3    = 1
	SYN_REPLYv3     = 2
	RST_STREAMv3    = 3
	SETTINGSv3      = 4
	PINGv3          = 6
	GOAWAYv3        = 7
	HEADERSv3       = 8
	WINDOW_UPDATEv3 = 9
	CREDENTIALv3    = 10
	CONTROL_FRAMEv3 = -1
	DATA_FRAMEv3    = -2
)

Frame types in SPDY/3

View Source
const (
	FLAG_FIN                     = 1
	FLAG_UNIDIRECTIONAL          = 2
	FLAG_SETTINGS_CLEAR_SETTINGS = 1
	FLAG_SETTINGS_PERSIST_VALUE  = 1
	FLAG_SETTINGS_PERSISTED      = 2
)

Flags

View Source
const (
	RST_STREAM_PROTOCOL_ERROR        = 1
	RST_STREAM_INVALID_STREAM        = 2
	RST_STREAM_REFUSED_STREAM        = 3
	RST_STREAM_UNSUPPORTED_VERSION   = 4
	RST_STREAM_CANCEL                = 5
	RST_STREAM_INTERNAL_ERROR        = 6
	RST_STREAM_FLOW_CONTROL_ERROR    = 7
	RST_STREAM_STREAM_IN_USE         = 8
	RST_STREAM_STREAM_ALREADY_CLOSED = 9
	RST_STREAM_INVALID_CREDENTIALS   = 10
	RST_STREAM_FRAME_TOO_LARGE       = 11
)

RST_STREAM status codes

View Source
const (
	GOAWAY_OK                 = 0
	GOAWAY_PROTOCOL_ERROR     = 1
	GOAWAY_INTERNAL_ERROR     = 2
	GOAWAY_FLOW_CONTROL_ERROR = 3
)

GOAWAY status codes

View Source
const (
	SETTINGS_UPLOAD_BANDWIDTH               = 1
	SETTINGS_DOWNLOAD_BANDWIDTH             = 2
	SETTINGS_ROUND_TRIP_TIME                = 3
	SETTINGS_MAX_CONCURRENT_STREAMS         = 4
	SETTINGS_CURRENT_CWND                   = 5
	SETTINGS_DOWNLOAD_RETRANS_RATE          = 6
	SETTINGS_INITIAL_WINDOW_SIZE            = 7
	SETTINGS_CLIENT_CERTIFICATE_VECTOR_SIZE = 8
)

Settings IDs

View Source
const DEFAULT_INITIAL_CLIENT_WINDOW_SIZE = 10485760

The default initial transfer window sent by the client.

View Source
const DEFAULT_INITIAL_WINDOW_SIZE = 65535

The default initial transfer window size, as defined in the spec.

View Source
const DEFAULT_STREAM_LIMIT = 1000

The default maximum number of concurrent streams.

View Source
const MAX_DATA_SIZE = 0xffffff
View Source
const MAX_DELTA_WINDOW_SIZE = 0x7fffffff

Maximum delta window size field for WINDOW_UPDATE.

View Source
const MAX_FRAME_SIZE = 0xffffff

Maximum frame size (2 ** 24 -1).

View Source
const MAX_STREAM_ID = 0x7fffffff

Maximum stream ID (2 ** 31 -1).

View Source
const MAX_TRANSFER_WINDOW_SIZE = 0x80000000

Maximum number of bytes in the transfer window.

View Source
const NO_STREAM_LIMIT = 0x80000000

NO_STREAM_LIMIT can be used to disable the stream limit.

Variables

View Source
var (
	ErrConnNil        = errors.New("Error: Connection is nil.")
	ErrConnClosed     = errors.New("Error: Connection is closed.")
	ErrGoaway         = errors.New("Error: GOAWAY received.")
	ErrNoFlowControl  = errors.New("Error: This connection does not use flow control.")
	ErrConnectFail    = errors.New("Error: Failed to connect.")
	ErrInvalidVersion = errors.New("Error: Invalid SPDY version.")

	// ErrNotSPDY indicates that a SPDY-specific feature was attempted
	// with a ResponseWriter using a non-SPDY connection.
	ErrNotSPDY = errors.New("Error: Not a SPDY connection.")

	// ErrNotConnected indicates that a SPDY-specific feature was
	// attempted with a Client not connected to the given server.
	ErrNotConnected = errors.New("Error: Not connected to given server.")
)
View Source
var CompressionLevel = zlib.BestCompression

CompressionLevel can be used to customise the level of compression used when sending headers.

View Source
var FrameTooLarge = errors.New("Error: Frame too large.")
View Source
var HeaderDictionaryV2 = []byte{}/* 907 elements not displayed */

Compression header for SPDY/2

View Source
var HeaderDictionaryV3 = []byte{}/* 1423 elements not displayed */

Compression header for SPDY/3

View Source
var MaxBenignErrors = 0

MaxBenignErrors is the maximum number of minor errors each connection will allow without ending the session.

By default, MaxBenignErrors is set to 0, disabling checks and allowing minor errors to go unchecked, although they will still be reported to the debug logger. If it is important that no errors go unchecked, such as when testing another implementation, set MaxBenignErrors to 1 or higher.

View Source
var StreamIdIsZero = errors.New("Error: Stream ID is zero.")
View Source
var StreamIdTooLarge = errors.New("Error: Stream ID is too large.")
View Source
var VerboseLogging = false

Functions

func BytesToUint16

func BytesToUint16(b []byte) uint16

func BytesToUint24

func BytesToUint24(b []byte) uint32

func BytesToUint24Reverse

func BytesToUint24Reverse(b []byte) uint32

func BytesToUint32

func BytesToUint32(b []byte) uint32

func CloneHeader

func CloneHeader(h http.Header) http.Header

CloneHeader returns a duplicate of the provided Header.

func EnableDebugOutput

func EnableDebugOutput()

EnableDebugOutput sets the output for the package's debug info logger to os.Stdout.

func IncorrectDataLength

func IncorrectDataLength(got, expected int) error

func IncorrectFrame

func IncorrectFrame(got, expected, version int) error

func InvalidField

func InvalidField(field string, got, expected int) error

func ReadExactly

func ReadExactly(r io.Reader, i int) ([]byte, error)

ReadExactly is used to ensure that the given number of bytes are read if possible, even if multiple calls to Read are required.

func Recover

func Recover()

func SetDebugLogger

func SetDebugLogger(l *logging.Logger)

SetDebugLogger sets the package's debug info logger.

func SetDebugOutput

func SetDebugOutput(w io.Writer)

SetDebugOutput sets the output for the package's debug info logger.

func SetLogOutput

func SetLogOutput(w io.Writer)

SetLogOutput sets the output for the package's error logger.

func SetLogger

func SetLogger(l *logging.Logger)

SetLogger sets the package's error logger.

func UpdateHeader

func UpdateHeader(older, newer http.Header)

UpdateHeader adds and new name/value pairs and replaces those already existing in the older header.

func WriteExactly

func WriteExactly(w io.Writer, data []byte) error

WriteExactly is used to ensure that the given data is written if possible, even if multiple calls to Write are required.

Types

type Compressor

type Compressor interface {
	io.Closer
	Compress(http.Header) ([]byte, error)
}

Compressor is used to compress the text header of a SPDY frame.

func NewCompressor

func NewCompressor(version uint16) Compressor

NewCompressor is used to create a new compressor. It takes the SPDY version to use.

type Conn

type Conn interface {
	http.CloseNotifier
	Close() error
	Closed() bool
	Conn() net.Conn
	Request(request *http.Request, receiver Receiver, priority Priority) (Stream, error)
	RequestResponse(request *http.Request, receiver Receiver, priority Priority) (*http.Response, error)
	Run() error
}

Connection represents a SPDY connection. The connection should be started with a call to Run, which will return once the connection has been terminated. The connection can be ended early by using Close.

type Decompressor

type Decompressor interface {
	Decompress([]byte) (http.Header, error)
}

Decompressor is used to decompress the text header of a SPDY frame.

func NewDecompressor

func NewDecompressor(version uint16) Decompressor

NewDecompressor is used to create a new decompressor. It takes the SPDY version to use.

type Flags

type Flags byte

Flags represent a frame's Flags.

func (Flags) CLEAR_SETTINGS

func (f Flags) CLEAR_SETTINGS() bool

CLEAR_SETTINGS indicates whether the CLEAR_SETTINGS flag is set.

func (Flags) FIN

func (f Flags) FIN() bool

FIN indicates whether the FIN flag is set.

func (Flags) PERSISTED

func (f Flags) PERSISTED() bool

PERSISTED indicates whether the PERSISTED flag is set.

func (Flags) PERSIST_VALUE

func (f Flags) PERSIST_VALUE() bool

PERSIST_VALUE indicates whether the PERSIST_VALUE flag is set.

func (Flags) UNIDIRECTIONAL

func (f Flags) UNIDIRECTIONAL() bool

UNIDIRECTIONAL indicates whether the UNIDIRECTIONAL flag is set.

type FlowControl

type FlowControl interface {
	InitialWindowSize() uint32
	ReceiveData(streamID StreamID, initialWindowSize uint32, newWindowSize int64) (deltaSize uint32)
}

Objects conforming to the FlowControl interface can be used to provide the flow control mechanism for a connection using SPDY version 3 and above.

InitialWindowSize is called whenever a new stream is created, and the returned value used as the initial flow control window size. Note that a values smaller than the default (65535) will likely result in poor network utilisation.

ReceiveData is called whenever a stream's window is consumed by inbound data. The stream's ID is provided, along with the stream's initial window size and the current window size after receiving the data that caused the call. If the window is to be regrown, ReceiveData should return the increase in size. A value of 0 does not change the window. Note that in SPDY/3.1 and later, the streamID may be 0 to represent the connection-level flow control window.

type Frame

type Frame interface {
	fmt.Stringer
	io.ReaderFrom
	io.WriterTo
	Compress(Compressor) error
	Decompress(Decompressor) error
	Name() string
}

Frame represents a single SPDY frame.

type Logger

type Logger struct {
	*logging.Logger
}

func GetDebugLogger

func GetDebugLogger() *Logger

func GetLogger

func GetLogger() *Logger

type Pinger

type Pinger interface {
	Ping() (<-chan bool, error)
}

Pinger represents something able to send and receive PING frames.

type Priority

type Priority byte

Priority represents a stream's priority.

func DefaultPriority

func DefaultPriority(url *url.URL) Priority

DefaultPriority returns the default request priority for the given target path. This is currently in accordance with Google Chrome; giving 0 for pages, 1 for CSS, 2 for JS, 3 for images. Other types default to 2.

func (Priority) Byte

func (p Priority) Byte(version uint16) byte

Byte returns the priority in binary form, adjusted for the given SPDY version.

func (Priority) Valid

func (p Priority) Valid(version uint16) bool

Valid indicates whether the priority is in the valid range for the given SPDY version.

type PriorityStream

type PriorityStream interface {
	Stream

	// Priority returns the stream's
	// priority.
	Priority() Priority
}

PriorityStream represents a SPDY stream with a priority.

type PushStream

type PushStream interface {
	Stream

	// Fin is used to close the
	// push stream once writing
	// has finished.
	Finish()
}

PushStream contains a single SPDY push stream.

type Pusher

type Pusher interface {
	Push(url string, origin Stream) (PushStream, error)
}

Pusher represents something able to send server puhes.

type ReadCloser

type ReadCloser struct {
	io.Reader
}

ReadCloser is a helper structure to allow an io.Reader to satisfy the io.ReadCloser interface.

func (*ReadCloser) Close

func (r *ReadCloser) Close() error

type ReadCounter

type ReadCounter struct {
	N int64
	R io.Reader
}

ReadCounter is a helper structure for keeping track of the number of bytes read from an io.Reader

func (*ReadCounter) Read

func (r *ReadCounter) Read(b []byte) (n int, err error)

type Receiver

type Receiver interface {
	ReceiveData(request *http.Request, data []byte, final bool)
	ReceiveHeader(request *http.Request, header http.Header)
	ReceiveRequest(request *http.Request) bool
}

Objects implementing the Receiver interface can be registered to receive requests on the Client.

ReceiveData is passed the original request, the data to receive and a bool indicating whether this is the final batch of data. If the bool is set to true, the data may be empty, but should not be nil.

ReceiveHeaders is passed the request and any sent text headers. This may be called multiple times. Note that these headers may contain the status code of the response, under the ":status" header. If the Receiver is being used to proxy a request, and the headers presented to ReceiveHeader are copied to another ResponseWriter, take care to call its WriteHeader method after copying all headers, since this may flush headers received so far.

ReceiveRequest is used when server pushes are sent. The returned bool should inticate whether to accept the push. The provided Request will be that sent by the server with the push.

type Response

type Response struct {
	StatusCode int

	Header http.Header

	Request  *http.Request
	Receiver Receiver
	// contains filtered or unexported fields
}

Response is used in handling responses; storing the data as it's received, and producing an http.Response once complete.

Response may be given a Receiver to enable live handling of the response data. This is provided by setting spdy.Transport.Receiver. Note that providing a Receiver disables the default data storage so the returned http.Response.Body will be empty.

func NewResponse

func NewResponse(request *http.Request, receiver Receiver) *Response

func (*Response) ReceiveData

func (r *Response) ReceiveData(req *http.Request, data []byte, finished bool)

func (*Response) ReceiveHeader

func (r *Response) ReceiveHeader(req *http.Request, header http.Header)

func (*Response) ReceiveRequest

func (r *Response) ReceiveRequest(req *http.Request) bool

func (*Response) Response

func (r *Response) Response() *http.Response

type SetFlowController

type SetFlowController interface {
	SetFlowControl(FlowControl)
}

SetFlowController represents a connection which can have its flow control mechanism customised.

type Setting

type Setting struct {
	Flags Flags
	ID    uint32
	Value uint32
}

Setting represents a single setting as sent in a SPDY SETTINGS frame.

func (*Setting) String

func (s *Setting) String() string

String gives the textual representation of a Setting.

type Settings

type Settings map[uint32]*Setting

Settings represents a series of settings, stored in a map by setting ID. This ensures that duplicate settings are not sent, since the new value will replace the old.

func (Settings) Settings

func (s Settings) Settings() []*Setting

Settings returns a slice of Setting, sorted into order by ID, as in the SPDY specification.

type StatusCode

type StatusCode uint32

StatusCode represents a status code sent in certain SPDY frames, such as RST_STREAM and GOAWAY.

func (StatusCode) B1

func (r StatusCode) B1() byte

func (StatusCode) B2

func (r StatusCode) B2() byte

func (StatusCode) B3

func (r StatusCode) B3() byte

func (StatusCode) B4

func (r StatusCode) B4() byte

func (StatusCode) IsFatal

func (r StatusCode) IsFatal() bool

IsFatal returns a bool indicating whether receiving the given status code should end the connection.

func (StatusCode) String

func (r StatusCode) String() string

String gives the StatusCode in text form.

type Stream

type Stream interface {
	http.CloseNotifier
	http.ResponseWriter
	Close() error
	Conn() Conn
	ReceiveFrame(Frame) error
	Run() error
	State() *StreamState
	StreamID() StreamID
}

Stream contains a single SPDY stream.

type StreamID

type StreamID uint32

StreamID is the unique identifier for a single SPDY stream.

func (StreamID) B1

func (s StreamID) B1() byte

func (StreamID) B2

func (s StreamID) B2() byte

func (StreamID) B3

func (s StreamID) B3() byte

func (StreamID) B4

func (s StreamID) B4() byte

func (StreamID) Client

func (s StreamID) Client() bool

Client indicates whether the ID should belong to a client-sent stream.

func (StreamID) Server

func (s StreamID) Server() bool

Server indicates whether the ID should belong to a server-sent stream.

func (StreamID) Valid

func (s StreamID) Valid() bool

Valid indicates whether the ID is in the range of legal values (including 0).

func (StreamID) Zero

func (s StreamID) Zero() bool

Zero indicates whether the ID is zero.

type StreamLimit

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

StreamLimit is used to add and enforce a limit on the number of concurrently active streams.

func NewStreamLimit

func NewStreamLimit(limit uint32) *StreamLimit

func (*StreamLimit) Add

func (s *StreamLimit) Add() bool

Add is called when a new stream is to be opened. Add returns a bool indicating whether the stream is safe open.

func (*StreamLimit) Close

func (s *StreamLimit) Close()

Close is called when a stream is closed; thus freeing up a slot.

func (*StreamLimit) Limit

func (s *StreamLimit) Limit() uint32

Limit returns the current limit.

func (*StreamLimit) SetLimit

func (s *StreamLimit) SetLimit(l uint32)

SetLimit is used to modify the stream limit. If the limit is set to NO_STREAM_LIMIT, then the limiting is disabled.

type StreamState

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

StreamState is used to store and query the stream's state. The active methods do not directly affect the stream's state, but it will use that information to effect the changes.

func (*StreamState) Close

func (s *StreamState) Close()

Closes the stream.

func (*StreamState) CloseHere

func (s *StreamState) CloseHere()

Half-close the stream locally.

func (*StreamState) CloseThere

func (s *StreamState) CloseThere()

Half-close the stream at the other endpoint.

func (*StreamState) Closed

func (s *StreamState) Closed() bool

Check whether the stream is closed.

func (*StreamState) ClosedHere

func (s *StreamState) ClosedHere() bool

Check whether the stream is half-closed at the other endpoint.

func (*StreamState) ClosedThere

func (s *StreamState) ClosedThere() bool

Check whether the stream is half-closed at the other endpoint.

func (*StreamState) Open

func (s *StreamState) Open() bool

Check whether the stream is open.

func (*StreamState) OpenHere

func (s *StreamState) OpenHere() bool

Check whether the stream is open locally.

func (*StreamState) OpenThere

func (s *StreamState) OpenThere() bool

Check whether the stream is open at the other endpoint.

func (*StreamState) String

func (s *StreamState) String() string

State description.

type UnsupportedVersion

type UnsupportedVersion uint16

func (UnsupportedVersion) Error

func (u UnsupportedVersion) Error() string

type WriteCounter

type WriteCounter struct {
	N int64
	W io.Writer
}

WriteCounter is a helper structure for keeping track of the number of bytes written from an io.Writer

func (*WriteCounter) Write

func (w *WriteCounter) Write(b []byte) (n int, err error)

Jump to

Keyboard shortcuts

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