Skip to content

Commit c46f265

Browse files
tomberganbradfitz
authored andcommitted
http2: implement support for server push
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]>
1 parent 65dfc08 commit c46f265

File tree

6 files changed

+882
-151
lines changed

6 files changed

+882
-151
lines changed

http2/go18.go

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,21 @@
66

77
package http2
88

9-
import "crypto/tls"
9+
import (
10+
"crypto/tls"
11+
"net/http"
12+
)
1013

1114
func cloneTLSConfig(c *tls.Config) *tls.Config { return c.Clone() }
15+
16+
var _ http.Pusher = (*responseWriter)(nil)
17+
18+
// Push implements http.Pusher.
19+
func (w *responseWriter) Push(target string, opts *http.PushOptions) error {
20+
internalOpts := pushOptions{}
21+
if opts != nil {
22+
internalOpts.Method = opts.Method
23+
internalOpts.Header = opts.Header
24+
}
25+
return w.push(target, internalOpts)
26+
}

http2/http2.go

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,13 +78,23 @@ var (
7878

7979
type streamState int
8080

81+
// HTTP/2 stream states.
82+
//
83+
// See http://tools.ietf.org/html/rfc7540#section-5.1.
84+
//
85+
// For simplicity, the server code merges "reserved (local)" into
86+
// "half-closed (remote)". This is one less state transition to track.
87+
// The only downside is that we send PUSH_PROMISEs slightly less
88+
// liberally than allowable. More discussion here:
89+
// https://lists.w3.org/Archives/Public/ietf-http-wg/2016JulSep/0599.html
90+
//
91+
// "reserved (remote)" is omitted since the client code does not
92+
// support server push.
8193
const (
8294
stateIdle streamState = iota
8395
stateOpen
8496
stateHalfClosedLocal
8597
stateHalfClosedRemote
86-
stateResvLocal
87-
stateResvRemote
8898
stateClosed
8999
)
90100

@@ -93,8 +103,6 @@ var stateName = [...]string{
93103
stateOpen: "Open",
94104
stateHalfClosedLocal: "HalfClosedLocal",
95105
stateHalfClosedRemote: "HalfClosedRemote",
96-
stateResvLocal: "ResvLocal",
97-
stateResvRemote: "ResvRemote",
98106
stateClosed: "Closed",
99107
}
100108

0 commit comments

Comments
 (0)