Skip to content

Commit cf73bbf

Browse files
tomberganbradfitz
authored andcommitted
net/http: add an interface for server push
This interface will be implemented by golang.org/x/net/http2 in https://go-review.googlesource.com/c/29439/. Updates #13443 Change-Id: Ib6bdd403b0878cfe36fa9875c07c2c7239232556 Reviewed-on: https://go-review.googlesource.com/32012 Run-TryBot: Brad Fitzpatrick <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Brad Fitzpatrick <[email protected]>
1 parent 45b43f6 commit cf73bbf

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

src/net/http/http.go

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,3 +100,42 @@ var (
100100
_ io.WriterTo = NoBody
101101
_ io.ReadCloser = NoBody
102102
)
103+
104+
// PushOptions describes options for Pusher.Push.
105+
type PushOptions struct {
106+
// Method specifies the HTTP method for the promised request.
107+
// If set, it must be "GET" or "HEAD". Empty means "GET".
108+
Method string
109+
110+
// Header specifies additional promised request headers. This cannot
111+
// include HTTP/2 pseudo header fields like ":path" and ":scheme",
112+
// which will be added automatically.
113+
Header Header
114+
}
115+
116+
// Pusher is the interface implemented by ResponseWriters that support
117+
// HTTP/2 server push. For more background, see
118+
// https://tools.ietf.org/html/rfc7540#section-8.2.
119+
type Pusher interface {
120+
// Push initiates an HTTP/2 server push. This constructs a synthetic
121+
// request using the given target and options, serializes that request
122+
// into a PUSH_PROMISE frame, then dispatches that request using the
123+
// server's request handler. If opts is nil, default options are used.
124+
//
125+
// The target must either be an absolute path (like "/path") or an absolute
126+
// URL that contains a valid host and the same scheme as the parent request.
127+
// If the target is a path, it will inherit the scheme and host of the
128+
// parent request.
129+
//
130+
// The HTTP/2 spec disallows recursive pushes and cross-authority pushes.
131+
// Push may or may not detect these invalid pushes; however, invalid
132+
// pushes will be detected and canceled by conforming clients.
133+
//
134+
// Handlers that wish to push URL X should call Push before sending any
135+
// data that may trigger a request for URL X. This avoids a race where the
136+
// client issues requests for X before receiving the PUSH_PROMISE for X.
137+
//
138+
// Push returns ErrNotSupported if the client has disabled push or if push
139+
// is not supported on the underlying connection.
140+
Push(target string, opts *PushOptions) error
141+
}

0 commit comments

Comments
 (0)