aboutsummaryrefslogtreecommitdiff
path: root/src/net
diff options
context:
space:
mode:
authorTom Bergan <tombergan@google.com>2016-10-25 12:18:59 -0700
committerBrad Fitzpatrick <bradfitz@golang.org>2016-10-25 21:22:48 +0000
commitcf73bbfa259afe29962a5ca5e207441f63c9bcf2 (patch)
tree3635140506ba5759684b51cb71ef7373e7af9b20 /src/net
parent45b43f6198436b18a0b5f64a3176d632e4f1c855 (diff)
downloadgo-cf73bbfa259afe29962a5ca5e207441f63c9bcf2.tar.xz
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 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>
Diffstat (limited to 'src/net')
-rw-r--r--src/net/http/http.go39
1 files changed, 39 insertions, 0 deletions
diff --git a/src/net/http/http.go b/src/net/http/http.go
index 40018453c6..826f7ff3da 100644
--- a/src/net/http/http.go
+++ b/src/net/http/http.go
@@ -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
+}