Documentation ¶
Overview ¶
Package common contains shared functionality for the spdy package.
Index ¶
- Constants
- Variables
- func BytesToUint16(b []byte) uint16
- func BytesToUint24(b []byte) uint32
- func BytesToUint24Reverse(b []byte) uint32
- func BytesToUint32(b []byte) uint32
- func CloneHeader(h http.Header) http.Header
- func EnableDebugOutput()
- func IncorrectDataLength(got, expected int) error
- func IncorrectFrame(got, expected, version int) error
- func InvalidField(field string, got, expected int) error
- func ReadExactly(r io.Reader, i int) ([]byte, error)
- func Recover()
- func SetDebugLogger(l *logging.Logger)
- func SetDebugOutput(w io.Writer)
- func SetLogOutput(w io.Writer)
- func SetLogger(l *logging.Logger)
- func UpdateHeader(older, newer http.Header)
- func WriteExactly(w io.Writer, data []byte) error
- type Compressor
- type Conn
- type Decompressor
- type Flags
- type FlowControl
- type Frame
- type Logger
- type Pinger
- type Priority
- type PriorityStream
- type PushStream
- type Pusher
- type ReadCloser
- type ReadCounter
- type Receiver
- type Response
- type SetFlowController
- type Setting
- type Settings
- type StatusCode
- type Stream
- type StreamID
- type StreamLimit
- type StreamState
- func (s *StreamState) Close()
- func (s *StreamState) CloseHere()
- func (s *StreamState) CloseThere()
- func (s *StreamState) Closed() bool
- func (s *StreamState) ClosedHere() bool
- func (s *StreamState) ClosedThere() bool
- func (s *StreamState) Open() bool
- func (s *StreamState) OpenHere() bool
- func (s *StreamState) OpenThere() bool
- func (s *StreamState) String() string
- type UnsupportedVersion
- type WriteCounter
Constants ¶
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
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
const ( FLAG_FIN = 1 FLAG_UNIDIRECTIONAL = 2 FLAG_SETTINGS_CLEAR_SETTINGS = 1 FLAG_SETTINGS_PERSIST_VALUE = 1 FLAG_SETTINGS_PERSISTED = 2 )
Flags
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
const ( GOAWAY_OK = 0 GOAWAY_PROTOCOL_ERROR = 1 GOAWAY_INTERNAL_ERROR = 2 GOAWAY_FLOW_CONTROL_ERROR = 3 )
GOAWAY status codes
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
const DEFAULT_INITIAL_CLIENT_WINDOW_SIZE = 10485760
The default initial transfer window sent by the client.
const DEFAULT_INITIAL_WINDOW_SIZE = 65535
The default initial transfer window size, as defined in the spec.
const DEFAULT_STREAM_LIMIT = 1000
The default maximum number of concurrent streams.
const MAX_DATA_SIZE = 0xffffff
const MAX_DELTA_WINDOW_SIZE = 0x7fffffff
Maximum delta window size field for WINDOW_UPDATE.
const MAX_FRAME_SIZE = 0xffffff
Maximum frame size (2 ** 24 -1).
const MAX_STREAM_ID = 0x7fffffff
Maximum stream ID (2 ** 31 -1).
const MAX_TRANSFER_WINDOW_SIZE = 0x80000000
Maximum number of bytes in the transfer window.
const NO_STREAM_LIMIT = 0x80000000
NO_STREAM_LIMIT can be used to disable the stream limit.
Variables ¶
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.") )
var CompressionLevel = zlib.BestCompression
CompressionLevel can be used to customise the level of compression used when sending headers.
var FrameTooLarge = errors.New("Error: Frame too large.")
var HeaderDictionaryV2 = []byte{}/* 907 elements not displayed */
Compression header for SPDY/2
var HeaderDictionaryV3 = []byte{}/* 1423 elements not displayed */
Compression header for SPDY/3
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.
var StreamIdIsZero = errors.New("Error: Stream ID is zero.")
var StreamIdTooLarge = errors.New("Error: Stream ID is too large.")
var VerboseLogging = false
Functions ¶
func BytesToUint16 ¶
func BytesToUint24 ¶
func BytesToUint24Reverse ¶
func BytesToUint32 ¶
func CloneHeader ¶
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 IncorrectFrame ¶
func InvalidField ¶
func ReadExactly ¶
ReadExactly is used to ensure that the given number of bytes are read if possible, even if multiple calls to Read are required.
func SetDebugLogger ¶
SetDebugLogger sets the package's debug info logger.
func SetDebugOutput ¶
SetDebugOutput sets the output for the package's debug info logger.
func SetLogOutput ¶
SetLogOutput sets the output for the package's error logger.
func UpdateHeader ¶
UpdateHeader adds and new name/value pairs and replaces those already existing in the older header.
Types ¶
type Compressor ¶
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 ¶
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 ¶
CLEAR_SETTINGS indicates whether the CLEAR_SETTINGS flag is set.
func (Flags) PERSIST_VALUE ¶
PERSIST_VALUE indicates whether the PERSIST_VALUE flag is set.
func (Flags) UNIDIRECTIONAL ¶
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 ¶
func GetDebugLogger ¶
func GetDebugLogger() *Logger
type Priority ¶
type Priority byte
Priority represents a stream's priority.
func DefaultPriority ¶
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.
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 ¶
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 ¶
ReadCounter is a helper structure for keeping track of the number of bytes read from an io.Reader
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 (*Response) ReceiveData ¶
func (*Response) ReceiveHeader ¶
type SetFlowController ¶
type SetFlowController interface {
SetFlowControl(FlowControl)
}
SetFlowController represents a connection which can have its flow control mechanism customised.
type Settings ¶
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.
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.
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) 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) 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) 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.
type UnsupportedVersion ¶
type UnsupportedVersion uint16
func (UnsupportedVersion) Error ¶
func (u UnsupportedVersion) Error() string