http2: github.com/Jxck/http2 Index | Files | Directories

package http2

import "github.com/Jxck/http2"

Index

Package Files

body.go conn.go response_writer.go server.go setting.go state.go stream.go transport.go url.go util.go window.go

Constants

const (
    OVER_TLS           string = "h2"
    OVER_TCP                  = "h2c"
    VERSION                   = OVER_TLS
    CONNECTION_PREFACE        = "PRI * HTTP/2.0\r\n\r\nSM\r\n\r\n"
)

Variables

var (
    NextClientStreamID chan uint32 = util.NextID(1)
    NextServerStreamID chan uint32 = util.NextID(2)
)
var DefaultSettings = map[SettingsID]int32{
    SETTINGS_HEADER_TABLE_SIZE: DEFAULT_HEADER_TABLE_SIZE,

    SETTINGS_MAX_CONCURRENT_STREAMS: DEFAULT_MAX_CONCURRENT_STREAMS,
    SETTINGS_INITIAL_WINDOW_SIZE:    DEFAULT_INITIAL_WINDOW_SIZE,
    SETTINGS_MAX_FRAME_SIZE:         DEFAULT_MAX_FRAME_SIZE,
    SETTINGS_MAX_HEADER_LIST_SIZE:   DEFAULT_MAX_HEADER_LIST_SIZE,
}
var MustHeader = map[string]string{
    ":authority": "authority",
    ":method":    "method",
    ":path":      "path",
    ":scheme":    "scheme",
    ":status":    "status",

    "Authority": ":authority",
    "Method":    ":method",
    "Path":      ":path",
    "Scheme":    ":scheme",
    "Status":    ":status",
}

Must Header with prefix

var NilSettings = make(map[SettingsID]int32, 0)
var TLSNextProto = map[string]func(*http.Server, *tls.Conn, http.Handler){
    VERSION: TLSNextProtoHandler,
}
var TLSNextProtoHandler = func(server *http.Server, conn *tls.Conn, handler http.Handler) {
    Notice(Yellow("New Connection from %s"), conn.RemoteAddr())
    HandleTLSConnection(conn, handler)
    return
}

func HandleTLSConnection Uses

func HandleTLSConnection(conn net.Conn, handler http.Handler)

type Body Uses

type Body struct {
    bytes.Buffer
}

func (*Body) Close Uses

func (b *Body) Close() error

type Bucket Uses

type Bucket struct {
    Headers http.Header
    Body    *Body
}

func NewBucket Uses

func NewBucket() *Bucket

type CallBack Uses

type CallBack func(stream *Stream)

func HandlerCallBack Uses

func HandlerCallBack(handler http.Handler) CallBack

handler を受け取って、将来 stream が渡されたら その Bucket につめられた Headers/Data フレームから req/res を作って handler を実行する関数を生成

func TransportCallBack Uses

func TransportCallBack(req *http.Request) (CallBack, chan *http.Response)

type Conn Uses

type Conn struct {
    RW           io.ReadWriter
    HpackContext *hpack.Context
    LastStreamID uint32
    Window       *Window
    Settings     map[SettingsID]int32
    PeerSettings map[SettingsID]int32
    Streams      map[uint32]*Stream
    WriteChan    chan Frame
    CallBack     func(stream *Stream)
}

func NewConn Uses

func NewConn(rw io.ReadWriter) *Conn

func (*Conn) Close Uses

func (conn *Conn) Close()

func (*Conn) GoAway Uses

func (conn *Conn) GoAway(streamId uint32, h2Error *H2Error)

func (*Conn) HandleSettings Uses

func (conn *Conn) HandleSettings(settingsFrame *SettingsFrame)

func (*Conn) NewStream Uses

func (conn *Conn) NewStream(streamid uint32) *Stream

func (*Conn) PingACK Uses

func (conn *Conn) PingACK(opaqueData []byte)

func (*Conn) ReadLoop Uses

func (conn *Conn) ReadLoop()

func (*Conn) ReadMagic Uses

func (conn *Conn) ReadMagic() (err error)

func (*Conn) WindowConsume Uses

func (conn *Conn) WindowConsume(length int32)

func (*Conn) WriteLoop Uses

func (conn *Conn) WriteLoop() (err error)

func (*Conn) WriteMagic Uses

func (conn *Conn) WriteMagic() (err error)

type Context Uses

type Context int
const (
    RECV Context = iota
    SEND
)

func (Context) String Uses

func (c Context) String() string

type ResponseWriter Uses

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

func NewResponseWriter Uses

func NewResponseWriter() *ResponseWriter

func (*ResponseWriter) Header Uses

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

func (ResponseWriter) String Uses

func (r ResponseWriter) String() (str string)

func (*ResponseWriter) Write Uses

func (r *ResponseWriter) Write(b []byte) (int, error)

func (*ResponseWriter) WriteHeader Uses

func (r *ResponseWriter) WriteHeader(status int)

type State Uses

type State int

state of stream

const (
    IDLE State = iota
    RESERVED_LOCAL
    RESERVED_REMOTE
    OPEN
    HALF_CLOSED_LOCAL
    HALF_CLOSED_REMOTE
    CLOSED
)

func (State) String Uses

func (s State) String() string

type Stream Uses

type Stream struct {
    ID           uint32
    State        State
    Window       *Window
    ReadChan     chan Frame
    WriteChan    chan Frame
    Settings     map[SettingsID]int32
    PeerSettings map[SettingsID]int32
    HpackContext *hpack.Context
    CallBack     CallBack
    Bucket       *Bucket
    Closed       bool
}

func NewStream Uses

func NewStream(id uint32, writeChan chan Frame, settings, peerSettings map[SettingsID]int32, hpackContext *hpack.Context, callback CallBack) *Stream

func (*Stream) ChangeState Uses

func (stream *Stream) ChangeState(frame Frame, context Context) (err error)

Stream States

                  +--------+
          send PP |        | recv PP
         ,--------|  idle  |--------.
        /         |        |         \
       v          +--------+          v
+----------+          |           +----------+
|          |          | send H /  |          |

,------| reserved | | recv H | reserved |------. | | (local) | | | (remote) | | | +----------+ v +----------+ | | | +--------+ | | | | recv ES | | send ES | | | send H | ,-------| open |-------. | recv H | | | / | | \ | | | v v +--------+ v v | | +----------+ | +----------+ | | | half | | | half | | | | closed | | send R / | closed | | | | (remote) | | recv R | (local) | | | +----------+ | +----------+ | | | | | | | | send ES / | recv ES / | | | | send R / v send R / | | | | recv R +--------+ recv R | | | send R / `----------->| |<-----------' send R / | | recv R | closed | recv R | `----------------------->| |<----------------------'

                      +--------+

send:   endpoint sends this frame
recv:   endpoint receives this frame

H:  HEADERS frame (with implied CONTINUATIONs)
PP: PUSH_PROMISE frame (with implied CONTINUATIONs)
ES: END_STREAM flag
R:  RST_STREAM frame

func (*Stream) Close Uses

func (stream *Stream) Close()

func (*Stream) DecodeHeader Uses

func (stream *Stream) DecodeHeader(headerBlockFragment []byte) http.Header

Decode Header using HPACK

func (*Stream) EncodeHeader Uses

func (stream *Stream) EncodeHeader(header http.Header) []byte

Encode Header using HPACK

func (*Stream) Read Uses

func (stream *Stream) Read(f Frame)

func (*Stream) ReadLoop Uses

func (stream *Stream) ReadLoop()

func (*Stream) WindowUpdate Uses

func (stream *Stream) WindowUpdate(length int32)

func (*Stream) Write Uses

func (stream *Stream) Write(frame Frame)

type Transport Uses

type Transport struct {
    Conn     *Conn
    CertPath string
    KeyPath  string
}

Transport implements http.RoundTriper with RoundTrip(request) response

func (*Transport) Connect Uses

func (transport *Transport) Connect(url *URL) (err error)

connect tcp connection with host

func (*Transport) RoundTrip Uses

func (transport *Transport) RoundTrip(req *http.Request) (res *http.Response, err error)

http.RoundTriper implementation

type URL Uses

type URL struct {
    *neturl.URL
    Port string
}

Exted net/url with adding Port because tls.Dial needs port number

func NewURL Uses

func NewURL(rawurl string) (*URL, error)

func (*URL) SplitHostPort Uses

func (url *URL) SplitHostPort() (err error)

TODO: net#SplitHostPort

type Util Uses

type Util struct{}

func (Util) Indent Uses

func (u Util) Indent(v interface{}) string

func (Util) NextID Uses

func (u Util) NextID(id uint32) chan uint32

func (Util) RequestString Uses

func (u Util) RequestString(req *http.Request) string

func (Util) ResponseString Uses

func (u Util) ResponseString(res *http.Response) string

func (Util) UpgradeRequest Uses

func (u Util) UpgradeRequest(req *http.Request, url *URL) *http.Request

type Window Uses

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

func NewWindow Uses

func NewWindow(initialWindow, peerInitilaWindow int32) *Window

func NewWindowDefault Uses

func NewWindowDefault() *Window

func (*Window) Consumable Uses

func (window *Window) Consumable(length int32) int32

func (*Window) Consume Uses

func (window *Window) Consume(length int32) (update int32)

func (*Window) ConsumePeer Uses

func (window *Window) ConsumePeer(length int32)

func (*Window) String Uses

func (window *Window) String() string

func (*Window) Update Uses

func (window *Window) Update(windowSizeIncrement int32)

func (*Window) UpdateInitialSize Uses

func (window *Window) UpdateInitialSize(newInitialWindowSize int32)

func (*Window) UpdatePeer Uses

func (window *Window) UpdatePeer(windowSizeIncrement int32)

Directories

PathSynopsis
frame
main
sample

Package http2 imports 15 packages (graph) and is imported by 2 packages. Updated 2016-07-21. Refresh now. Tools for package owners.