github.com/caddyserver/caddy/v2/modules/caddyhttp/push
No package summary is available.
Package
Files: 3. Third party imports: 2. Imports from organisation: 0. Tests: 0. Benchmarks: 0.
Constants
Vars
safeHeaders is a list of header fields that are safe to copy to push requests implicitly. It is assumed that requests for certain kinds of content would fail without these fields present.
Types
Handler
Handler is a middleware for HTTP/2 server push. Note that HTTP/2 server push has been deprecated by some clients and its use is discouraged unless you can accurately predict which resources actually need to be pushed to the client; it can be difficult to know what the client already has cached. Pushing unnecessary resources results in worse performance. Consider using HTTP 103 Early Hints instead.
This handler supports pushing from Link headers; in other words, if the eventual response has Link headers, this handler will push the resources indicated by those headers, even without specifying any resources in its config.
| Field name | Field type | Comment |
|---|---|---|
| Resources |
|
The resources to push. |
| Headers |
|
Headers to modify for the push requests. |
| logger |
|
No comment on field. |
HeaderConfig
HeaderConfig configures headers for synthetic push requests.
| Field name | Field type | Comment |
|---|---|---|
|
No comment on field. |
Resource
Resource represents a request for a resource to push.
| Field name | Field type | Comment |
|---|---|---|
| Method |
|
Method is the request method, which must be GET or HEAD. Default is GET. |
| Target |
|
Target is the path to the resource being pushed. |
linkPusher
linkPusher is a http.ResponseWriter that intercepts the WriteHeader() call to ensure that any resources described by Link response headers get pushed before the response is allowed to be written.
| Field name | Field type | Comment |
|---|---|---|
|
No comment on field. | |
| handler |
|
No comment on field. |
| pusher |
|
No comment on field. |
| header |
|
No comment on field. |
| request |
|
No comment on field. |
linkResource
linkResource contains the results of a parsed Link header.
| Field name | Field type | Comment |
|---|---|---|
| uri |
|
No comment on field. |
| params |
|
No comment on field. |
Functions
func (*Handler) Provision
Provision sets up h.
Uses: fmt.Errorf.func (Handler) CaddyModule
CaddyModule returns the Caddy module information.
func (Handler) ServeHTTP
func (linkPusher) WriteHeader
Private functions
func init
func isRemoteResource
isRemoteResource returns true if resource starts with a scheme or is a protocol-relative URI.
References: strings.HasPrefix.func parseCaddyfile
parseCaddyfile sets up the push handler. Syntax:
push [<matcher>] [<resource>] {
[GET|HEAD] <resource>
headers {
[+]<field> [<value|regexp> [<replacement>]]
-<field>
}
}
A single resource can be specified inline without opening a block for the most common/simple case. Or, a block can be opened and multiple resources can be specified, one per line, optionally preceded by the method. The headers subdirective can be used to customize the headers that are set on each (synthetic) push request, using the same syntax as the 'header' directive for request headers. Placeholders are accepted in resource and header field name and value and replacement tokens.
References: headers.CaddyfileHeaderOp.func parseLinkHeader
parseLinkHeader is responsible for parsing Link header and returning list of found resources.
Accepted formats are:
Link: <resource>; as=script
Link: <resource>; as=script,<resource>; as=style
Link: <resource>;<resource2>
where <resource> begins with a forward slash (/).
References: strings.Cut, strings.Index, strings.Split, strings.TrimSpace.func initializePushHeaders
func servePreloadLinks
servePreloadLinks parses Link headers from upstream and pushes resources described by them. If a resource has the "nopush" attribute or describes an external entity (meaning, the resource URI includes a scheme), it will not be pushed.
References: http.PushOptions.Tests
Files: 1. Third party imports: 0. Imports from organisation: 0. Tests: 1. Benchmarks: 0.