]> Cypherpunks repositories - gostls13.git/commitdiff
net/http: add an interface for server push
authorTom Bergan <tombergan@google.com>
Tue, 25 Oct 2016 19:18:59 +0000 (12:18 -0700)
committerBrad Fitzpatrick <bradfitz@golang.org>
Tue, 25 Oct 2016 21:22:48 +0000 (21:22 +0000)
This interface will be implemented by golang.org/x/net/http2 in
https://go-review.googlesource.com/c/29439/.

Updates golang/go#13443

Change-Id: Ib6bdd403b0878cfe36fa9875c07c2c7239232556
Reviewed-on: https://go-review.googlesource.com/32012
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
src/net/http/http.go

index 40018453c6f1592da9d7f2cec85c2b35ec9a2898..826f7ff3da5bd01165668e0c8267aac79281c25f 100644 (file)
@@ -100,3 +100,42 @@ var (
        _ io.WriterTo   = NoBody
        _ io.ReadCloser = NoBody
 )
+
+// PushOptions describes options for Pusher.Push.
+type PushOptions struct {
+       // Method specifies the HTTP method for the promised request.
+       // If set, it must be "GET" or "HEAD". Empty means "GET".
+       Method string
+
+       // Header specifies additional promised request headers. This cannot
+       // include HTTP/2 pseudo header fields like ":path" and ":scheme",
+       // which will be added automatically.
+       Header Header
+}
+
+// Pusher is the interface implemented by ResponseWriters that support
+// HTTP/2 server push. For more background, see
+// https://tools.ietf.org/html/rfc7540#section-8.2.
+type Pusher interface {
+       // Push initiates an HTTP/2 server push. This constructs a synthetic
+       // request using the given target and options, serializes that request
+       // into a PUSH_PROMISE frame, then dispatches that request using the
+       // server's request handler. If opts is nil, default options are used.
+       //
+       // The target must either be an absolute path (like "/path") or an absolute
+       // URL that contains a valid host and the same scheme as the parent request.
+       // If the target is a path, it will inherit the scheme and host of the
+       // parent request.
+       //
+       // The HTTP/2 spec disallows recursive pushes and cross-authority pushes.
+       // Push may or may not detect these invalid pushes; however, invalid
+       // pushes will be detected and canceled by conforming clients.
+       //
+       // Handlers that wish to push URL X should call Push before sending any
+       // data that may trigger a request for URL X. This avoids a race where the
+       // client issues requests for X before receiving the PUSH_PROMISE for X.
+       //
+       // Push returns ErrNotSupported if the client has disabled push or if push
+       // is not supported on the underlying connection.
+       Push(target string, opts *PushOptions) error
+}