spdy-go: github.com/shykes/spdy-go Index | Files | Directories

package spdy

import "github.com/shykes/spdy-go"

Package spdy implements the SPDY protocol which is described in draft-mbelshe-httpbis-spdy-00.

http://tools.ietf.org/html/draft-mbelshe-httpbis-spdy-00

Package spdy implements SPDY protocol which is described in draft-mbelshe-httpbis-spdy-00.

http://tools.ietf.org/html/draft-mbelshe-httpbis-spdy-00

Package spdy implements SPDY protocol which is described in draft-mbelshe-httpbis-spdy-00.

http://tools.ietf.org/html/draft-mbelshe-httpbis-spdy-00

Index

Package Files

http.go pipe.go read.go server.go session.go stream.go types.go util.go write.go

Constants

const HeaderDictionary = "optionsgetheadpostputdeletetrace" +
    "acceptaccept-charsetaccept-encodingaccept-languageauthorizationexpectfromhost" +
    "if-modified-sinceif-matchif-none-matchif-rangeif-unmodifiedsince" +
    "max-forwardsproxy-authorizationrangerefererteuser-agent" +
    "100101200201202203204205206300301302303304305306307400401402403404405406407408409410411412413414415416417500501502503504505" +
    "accept-rangesageetaglocationproxy-authenticatepublicretry-after" +
    "servervarywarningwww-authenticateallowcontent-basecontent-encodingcache-control" +
    "connectiondatetrailertransfer-encodingupgradeviawarning" +
    "content-languagecontent-lengthcontent-locationcontent-md5content-rangecontent-typeetagexpireslast-modifiedset-cookie" +
    "MondayTuesdayWednesdayThursdayFridaySaturdaySunday" +
    "JanFebMarAprMayJunJulAugSepOctNovDec" +
    "chunkedtext/htmlimage/pngimage/jpgimage/gifapplication/xmlapplication/xhtmltext/plainpublicmax-age" +
    "charset=iso-8859-1utf-8gzipdeflateHTTP/1.1statusversionurl\x00"

HeaderDictionary is the dictionary sent to the zlib compressor/decompressor. Even though the specification states there is no null byte at the end, Chrome sends it.

const MaxDataLength = 1<<24 - 1

MaxDataLength is the maximum number of bytes that can be stored in one frame.

const Version = 2

Version is the protocol version number that this package implements.

Variables

var DEBUG bool = false

func Copy Uses

func Copy(w Writer, r Reader) error

Copy copies from src to dst until either EOF is reached on src or an error occurs. It returns the first error encountered while copying, if any.

A successful Copy returns err == nil, not err == EOF. Because Copy is defined to read from src until EOF, it does not treat an EOF from Read as an error to be reported.

As a special case, if w is nil, all frames will be discarded.

func CopyBytes Uses

func CopyBytes(dst io.Writer, src Reader) error

CopyBytes reads frames from src, extracts payload data when it exists, and writes it to dst. It does so until either EOF is reached on src or an error occurs. It returns the first error encountered while copying, if any.

Frames without a payload (eg. every frame not of type DATA) are discarded.

func Extract Uses

func Extract(src Reader, data io.Writer, headers chan http.Header, drain Writer) error

func ExtractData Uses

func ExtractData(src Reader, data io.Writer) error

func ListenAndServe Uses

func ListenAndServe(listener net.Listener, handler Handler) error

func ListenAndServeTCP Uses

func ListenAndServeTCP(addr string, handler Handler) error

Listen on a TCP port, and pass new connections to a handler

func ListenAndServeTLS Uses

func ListenAndServeTLS(addr, certFile, keyFile string, handler Handler) error

func Promise Uses

func Promise(f func() error) chan error

func Splice Uses

func Splice(a ReadWriter, b ReadWriter, wait bool) error

Splice runs Copy(a, b) and Copy(b, a) in 2 distinct goroutines then waits for either one or both copies to complete, depending on the value of wait.

- If wait=true, Splice waits for both copies to complete and returns the first error encountered, if any. If both copies end with an error, it is undetermined which error is returned.

- If wait=false, Splice waits for one copy to complete and returns the first error encountered during that copy, if any. The other copy continues in the background.

func UpdateHeaders Uses

func UpdateHeaders(headers *http.Header, newHeaders *http.Header)

UpdateHeaders appends the contents of newHeaders to headers.

type ControlFlags Uses

type ControlFlags uint8

ControlFlags are the flags that can be set on a control frame.

const (
    ControlFlagFin ControlFlags = 0x01
)

type ControlFrameHeader Uses

type ControlFrameHeader struct {
    Flags ControlFlags
    // contains filtered or unexported fields
}

ControlFrameHeader contains all the fields in a control frame header, in its unpacked in-memory representation.

type ControlFrameType Uses

type ControlFrameType uint16

ControlFrameType stores the type field in a control frame header.

const (
    TypeSynStream    ControlFrameType = 0x0001
    TypeSynReply                      = 0x0002
    TypeRstStream                     = 0x0003
    TypeSettings                      = 0x0004
    TypeNoop                          = 0x0005
    TypePing                          = 0x0006
    TypeGoAway                        = 0x0007
    TypeHeaders                       = 0x0008
    TypeWindowUpdate                  = 0x0009
)

Control frame type constants

type DataFlags Uses

type DataFlags uint8

DataFlags are the flags that can be set on a data frame.

const (
    DataFlagFin        DataFlags = 0x01
    DataFlagCompressed           = 0x02
)

type DataFrame Uses

type DataFrame struct {
    // Note, high bit is the "Control" bit. Should be 0 for data frames.
    StreamId uint32
    Flags    DataFlags
    Data     []byte
}

DataFrame is the unpacked, in-memory representation of a DATA frame.

func (*DataFrame) GetFinFlag Uses

func (frame *DataFrame) GetFinFlag() bool

func (*DataFrame) GetHeaders Uses

func (frame *DataFrame) GetHeaders() *http.Header

func (*DataFrame) GetStreamId Uses

func (frame *DataFrame) GetStreamId() (uint32, bool)

type DummyHandler Uses

type DummyHandler struct{}

DummyHandler is an http.Handler which does nothing.

func (*DummyHandler) ServeHTTP Uses

func (f *DummyHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)

type Error Uses

type Error struct {
    Err      ErrorCode
    StreamId uint32
}

Error contains both the type of error and additional values. StreamId is 0 if Error is not associated with a stream.

func (*Error) Error Uses

func (e *Error) Error() string

func (*Error) ToFrame Uses

func (e *Error) ToFrame() *RstStreamFrame

Return a RST_STREAM frame containing a description of the error

type ErrorCode Uses

type ErrorCode string

A SPDY specific error.

const (
    UnlowercasedHeaderName     ErrorCode = "header was not lowercased"
    DuplicateHeaders           ErrorCode = "multiple headers with same name"
    WrongCompressedPayloadSize ErrorCode = "compressed payload size was incorrect"
    InvalidControlFrame        ErrorCode = "invalid control frame"
    InvalidDataFrame           ErrorCode = "invalid data frame"
    InvalidHeaderPresent       ErrorCode = "frame contained invalid header"
    ZeroStreamId               ErrorCode = "stream id zero is disallowed"
    IllegalSynStream           ErrorCode = "SYN_STREAM at the wrong time"
    IllegalSynReply            ErrorCode = "SYN_REPLY at the wrong time"
    IllegalFirstFrame          ErrorCode = "first frame must be SYN_STREAM or SYN_REPLY"
    StreamClosed               ErrorCode = "stream is closed"
    NoSuchStream               ErrorCode = "no such stream"
    InvalidStreamId            ErrorCode = "illegal stream id"
)

type Frame Uses

type Frame interface {

    // Return the Stream-ID of the frame if applicable,
    // and a bool to indicate whether a Stream-ID exists.
    GetStreamId() (uint32, bool)
    // Return the headers of the frame if applicable, or nil otherwise.
    GetHeaders() *http.Header
    // Returns whether the FIN flag is set for this frame.
    GetFinFlag() bool
    // contains filtered or unexported methods
}

Frame is a single SPDY frame in its unpacked in-memory representation. Use Framer to read and write it.

type Framer Uses

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

Framer handles serializing/deserializing SPDY frames, including compressing/ decompressing payloads.

func NewFramer Uses

func NewFramer(w io.Writer, r io.Reader) (*Framer, error)

NewFramer allocates a new Framer for a given SPDY connection, repesented by a io.Writer and io.Reader. Note that Framer will read and write individual fields from/to the Reader and Writer, so the caller should pass in an appropriately buffered implementation to optimize performance.

func (*Framer) ReadFrame Uses

func (f *Framer) ReadFrame() (Frame, error)

ReadFrame reads SPDY encoded data and returns a decompressed Frame.

func (*Framer) WriteFrame Uses

func (f *Framer) WriteFrame(frame Frame) error

WriteFrame writes a frame.

type GoAwayFrame Uses

type GoAwayFrame struct {
    CFHeader         ControlFrameHeader
    LastGoodStreamId uint32
}

GoAwayFrame is the unpacked, in-memory representation of a GOAWAY frame.

func (*GoAwayFrame) GetFinFlag Uses

func (frame *GoAwayFrame) GetFinFlag() bool

func (*GoAwayFrame) GetHeaders Uses

func (frame *GoAwayFrame) GetHeaders() *http.Header

func (*GoAwayFrame) GetStreamId Uses

func (frame *GoAwayFrame) GetStreamId() (uint32, bool)

type Handler Uses

type Handler http.Handler

type HeadersFrame Uses

type HeadersFrame struct {
    CFHeader ControlFrameHeader
    StreamId uint32
    Headers  http.Header
}

HeadersFrame is the unpacked, in-memory representation of a HEADERS frame.

func (*HeadersFrame) GetFinFlag Uses

func (frame *HeadersFrame) GetFinFlag() bool

func (*HeadersFrame) GetHeaders Uses

func (frame *HeadersFrame) GetHeaders() *http.Header

func (*HeadersFrame) GetStreamId Uses

func (frame *HeadersFrame) GetStreamId() (uint32, bool)

type NoopFrame Uses

type NoopFrame struct {
    CFHeader ControlFrameHeader
}

NoopFrame is the unpacked, in-memory representation of a NOOP frame.

func (*NoopFrame) GetFinFlag Uses

func (frame *NoopFrame) GetFinFlag() bool

func (*NoopFrame) GetHeaders Uses

func (frame *NoopFrame) GetHeaders() *http.Header

func (*NoopFrame) GetStreamId Uses

func (frame *NoopFrame) GetStreamId() (uint32, bool)

type PingFrame Uses

type PingFrame struct {
    CFHeader ControlFrameHeader
    Id       uint32
}

PingFrame is the unpacked, in-memory representation of a PING frame.

func (*PingFrame) GetFinFlag Uses

func (frame *PingFrame) GetFinFlag() bool

func (*PingFrame) GetHeaders Uses

func (frame *PingFrame) GetHeaders() *http.Header

func (*PingFrame) GetStreamId Uses

func (frame *PingFrame) GetStreamId() (uint32, bool)

type PipeReader Uses

type PipeReader struct {
    NFrames int
    // contains filtered or unexported fields
}

func Pipe Uses

func Pipe(buffer int) (*PipeReader, *PipeWriter)

func (*PipeReader) Close Uses

func (reader *PipeReader) Close() error

func (PipeReader) CloseWithError Uses

func (p PipeReader) CloseWithError(err error) error

func (*PipeReader) ReadFrame Uses

func (reader *PipeReader) ReadFrame() (Frame, error)

type PipeWriter Uses

type PipeWriter struct {
    NFrames int
    // contains filtered or unexported fields
}

func (*PipeWriter) Close Uses

func (writer *PipeWriter) Close() error

func (PipeWriter) CloseWithError Uses

func (p PipeWriter) CloseWithError(err error) error

func (*PipeWriter) WriteFrame Uses

func (writer *PipeWriter) WriteFrame(frame Frame) error

type ReadWriter Uses

type ReadWriter interface {
    Reader
    Writer
}

ReadWriter is the interface that groups the basic Read and Write methods.

type Reader Uses

type Reader interface {
    ReadFrame() (Frame, error)
}

Reader is the interface that wraps the basic ReadFrame method.

ReadFrame returns the next available frame, or an error indicating why the call failed. An error value of io.EOF indicates that the source of frames is closed.

If no frame is available, Read waits until there is one.

type ResponseWriter Uses

type ResponseWriter struct {
    *Stream
    // contains filtered or unexported fields
}

func (*ResponseWriter) Header Uses

func (w *ResponseWriter) Header() http.Header

func (*ResponseWriter) Write Uses

func (w *ResponseWriter) Write(data []byte) (int, error)

func (*ResponseWriter) WriteHeader Uses

func (w *ResponseWriter) WriteHeader(status int)

type RstStreamFrame Uses

type RstStreamFrame struct {
    CFHeader ControlFrameHeader
    StreamId uint32
    Status   StatusCode
}

RstStreamFrame is the unpacked, in-memory representation of a RST_STREAM frame.

func (*RstStreamFrame) GetFinFlag Uses

func (frame *RstStreamFrame) GetFinFlag() bool

func (*RstStreamFrame) GetHeaders Uses

func (frame *RstStreamFrame) GetHeaders() *http.Header

func (*RstStreamFrame) GetStreamId Uses

func (frame *RstStreamFrame) GetStreamId() (uint32, bool)

type Session Uses

type Session struct {
    Server bool // Are we the server? (necessary for stream ID numbering)
    // contains filtered or unexported fields
}

func DialTCP Uses

func DialTCP(addr string, handler Handler) (*Session, error)

Connect to a remote tcp server and return a new Session

func DialTLS Uses

func DialTLS(addr string, handler Handler) (*Session, error)

func NewSession Uses

func NewSession(handler http.Handler, server bool) *Session

func Serve Uses

func Serve(conn net.Conn, handler Handler, server bool) (*Session, error)

func (*Session) Close Uses

func (session *Session) Close()

func (*Session) CloseStream Uses

func (session *Session) CloseStream(id uint32) error

func (*Session) Closed Uses

func (session *Session) Closed() bool

func (*Session) InitiateStream Uses

func (session *Session) InitiateStream() (*Stream, error)

func (*Session) NStreams Uses

func (session *Session) NStreams() int

func (*Session) ReadFrame Uses

func (session *Session) ReadFrame() (Frame, error)

func (*Session) Serve Uses

func (session *Session) Serve(peer ReadWriter) error

func (*Session) WriteFrame Uses

func (session *Session) WriteFrame(frame Frame) error

type SettingsFlag Uses

type SettingsFlag uint8

SettingsFlag represents a flag in a SETTINGS frame.

const (
    FlagSettingsPersistValue SettingsFlag = 0x1
    FlagSettingsPersisted                 = 0x2
)

type SettingsFlagIdValue Uses

type SettingsFlagIdValue struct {
    Flag  SettingsFlag
    Id    SettingsId
    Value uint32
}

SettingsFlagIdValue is the unpacked, in-memory representation of the combined flag/id/value for a setting in a SETTINGS frame.

type SettingsFrame Uses

type SettingsFrame struct {
    CFHeader     ControlFrameHeader
    FlagIdValues []SettingsFlagIdValue
}

SettingsFrame is the unpacked, in-memory representation of a SPDY SETTINGS frame.

func (*SettingsFrame) GetFinFlag Uses

func (frame *SettingsFrame) GetFinFlag() bool

func (*SettingsFrame) GetHeaders Uses

func (frame *SettingsFrame) GetHeaders() *http.Header

func (*SettingsFrame) GetStreamId Uses

func (frame *SettingsFrame) GetStreamId() (uint32, bool)

type SettingsId Uses

type SettingsId uint32

SettingsFlag represents the id of an id/value pair in a SETTINGS frame.

const (
    SettingsUploadBandwidth      SettingsId = 1
    SettingsDownloadBandwidth               = 2
    SettingsRoundTripTime                   = 3
    SettingsMaxConcurrentStreams            = 4
    SettingsCurrentCwnd                     = 5
)

type StatusCode Uses

type StatusCode uint32

StatusCode represents the status that led to a RST_STREAM

const (
    ProtocolError       StatusCode = 1
    InvalidStream                  = 2
    RefusedStream                  = 3
    UnsupportedVersion             = 4
    Cancel                         = 5
    InternalError                  = 6
    FlowControlError               = 7
    StreamAlreadyClosed            = 9 // introduced in version 3
)

type Stream Uses

type Stream struct {
    Id  uint32

    Closed bool
    // contains filtered or unexported fields
}

func NewStream Uses

func NewStream(id uint32, local bool) (*Stream, *Stream)

func (*Stream) Close Uses

func (s *Stream) Close()

func (*Stream) CopyFrom Uses

func (s *Stream) CopyFrom(src io.Reader) error

func (*Stream) ParseHTTPRequest Uses

func (s *Stream) ParseHTTPRequest() (*http.Request, error)

func (*Stream) ReadFrame Uses

func (s *Stream) ReadFrame() (Frame, error)

func (*Stream) Reply Uses

func (s *Stream) Reply(headers *http.Header, fin bool) error

func (*Stream) Rst Uses

func (s *Stream) Rst(status StatusCode) error

func (*Stream) Serve Uses

func (stream *Stream) Serve(handler http.Handler)

func (*Stream) Syn Uses

func (s *Stream) Syn(headers *http.Header, fin bool) error

func (*Stream) WriteDataFrame Uses

func (s *Stream) WriteDataFrame(data []byte, fin bool) error

func (*Stream) WriteFrame Uses

func (s *Stream) WriteFrame(frame Frame) error

func (*Stream) WriteHeadersFrame Uses

func (s *Stream) WriteHeadersFrame(headers *http.Header, fin bool) error

type StreamPipeReader Uses

type StreamPipeReader struct {
    *PipeReader
}

func StreamPipe Uses

func StreamPipe(id uint32, reply bool) (*StreamPipeReader, *StreamPipeWriter)

func (StreamPipeReader) CloseWithError Uses

func (p StreamPipeReader) CloseWithError(err error) error

type StreamPipeWriter Uses

type StreamPipeWriter struct {
    *PipeWriter

    Headers http.Header
    // contains filtered or unexported fields
}

func (StreamPipeWriter) CloseWithError Uses

func (p StreamPipeWriter) CloseWithError(err error) error

func (*StreamPipeWriter) WriteFrame Uses

func (p *StreamPipeWriter) WriteFrame(frame Frame) error

type SynReplyFrame Uses

type SynReplyFrame struct {
    CFHeader ControlFrameHeader
    StreamId uint32
    Headers  http.Header
}

SynReplyFrame is the unpacked, in-memory representation of a SYN_REPLY frame.

func (*SynReplyFrame) GetFinFlag Uses

func (frame *SynReplyFrame) GetFinFlag() bool

func (*SynReplyFrame) GetHeaders Uses

func (frame *SynReplyFrame) GetHeaders() *http.Header

func (*SynReplyFrame) GetStreamId Uses

func (frame *SynReplyFrame) GetStreamId() (uint32, bool)

type SynStreamFrame Uses

type SynStreamFrame struct {
    CFHeader             ControlFrameHeader
    StreamId             uint32
    AssociatedToStreamId uint32
    // Note, only 2 highest bits currently used
    // Rest of Priority is unused.
    Priority uint16
    Headers  http.Header
}

SynStreamFrame is the unpacked, in-memory representation of a SYN_STREAM frame.

func (*SynStreamFrame) GetFinFlag Uses

func (frame *SynStreamFrame) GetFinFlag() bool

func (*SynStreamFrame) GetHeaders Uses

func (frame *SynStreamFrame) GetHeaders() *http.Header

func (*SynStreamFrame) GetStreamId Uses

func (frame *SynStreamFrame) GetStreamId() (uint32, bool)

type Writer Uses

type Writer interface {
    WriteFrame(Frame) error
}

Writer is the interface that wraps the basic WriteFrame method.

WriteFrame writes a frame to the underlying stream. It returns nil if the write is successful, or the error which caused it to fail.

Directories

PathSynopsis
examples

Package spdy imports 13 packages (graph) and is imported by 7 packages. Updated 2016-07-20. Refresh now. Tools for package owners.