Skip to content

Commit

Permalink
http2: implement support for server push
Browse files Browse the repository at this point in the history
This makes x/net/http2's ResponseWriter implement the new interface,
http.Pusher. This new interface requires Go 1.8. When compiled against
older versions of Go, the ResponseWriter does not have a Push method.

Fixes golang/go#13443

Change-Id: I8486ffe4bb5562a94270ace21e90e8c9a4653da0
Reviewed-on: https://go-review.googlesource.com/29439
Reviewed-by: Brad Fitzpatrick <[email protected]>
Run-TryBot: Brad Fitzpatrick <[email protected]>
  • Loading branch information
tombergan authored and bradfitz committed Oct 27, 2016
1 parent 544ea97 commit dd1e3a4
Show file tree
Hide file tree
Showing 6 changed files with 882 additions and 151 deletions.
17 changes: 16 additions & 1 deletion go18.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,21 @@

package http2

import "crypto/tls"
import (
"crypto/tls"
"net/http"
)

func cloneTLSConfig(c *tls.Config) *tls.Config { return c.Clone() }

var _ http.Pusher = (*responseWriter)(nil)

// Push implements http.Pusher.
func (w *responseWriter) Push(target string, opts *http.PushOptions) error {
internalOpts := pushOptions{}
if opts != nil {
internalOpts.Method = opts.Method
internalOpts.Header = opts.Header
}
return w.push(target, internalOpts)
}
16 changes: 12 additions & 4 deletions http2.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,23 @@ var (

type streamState int

// HTTP/2 stream states.
//
// See http://tools.ietf.org/html/rfc7540#section-5.1.
//
// For simplicity, the server code merges "reserved (local)" into
// "half-closed (remote)". This is one less state transition to track.
// The only downside is that we send PUSH_PROMISEs slightly less
// liberally than allowable. More discussion here:
// https://lists.w3.org/Archives/Public/ietf-http-wg/2016JulSep/0599.html
//
// "reserved (remote)" is omitted since the client code does not
// support server push.
const (
stateIdle streamState = iota
stateOpen
stateHalfClosedLocal
stateHalfClosedRemote
stateResvLocal
stateResvRemote
stateClosed
)

Expand All @@ -93,8 +103,6 @@ var stateName = [...]string{
stateOpen: "Open",
stateHalfClosedLocal: "HalfClosedLocal",
stateHalfClosedRemote: "HalfClosedRemote",
stateResvLocal: "ResvLocal",
stateResvRemote: "ResvRemote",
stateClosed: "Closed",
}

Expand Down
Loading

0 comments on commit dd1e3a4

Please sign in to comment.