mirror of
https://github.com/golang/go
synced 2024-11-18 08:04:40 -07:00
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>
This commit is contained in:
parent
45b43f6198
commit
cf73bbfa25
@ -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
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user