Documentation
¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type LinkPusher ¶
type LinkPusher struct {
Link string
}
LinkPusher pushes a link
func Push ¶
func Push(link string) *LinkPusher
Push pushs a link
Example ¶
Eagerly HTTP/2-push a single fixed asset on every request, before the downstream handler runs. The link is only pushed when the connection is HTTP/2 (the ResponseWriter is an http.Pusher); on HTTP/1.x it is a no-op.
package main
import (
"github.com/moonrhythm/parapet"
"github.com/moonrhythm/parapet/pkg/h2push"
)
func main() {
s := parapet.New()
s.Use(h2push.Push("/static/app.js"))
// s.Use(upstream.SingleHost("10.0.0.1:8080")) — the handler whose responses
// are served alongside the pushed asset.
}
Output:
func (LinkPusher) ServeHandler ¶
func (m LinkPusher) ServeHandler(h http.Handler) http.Handler
ServeHandler implements middleware interface
type PreloadPusher ¶
type PreloadPusher struct{}
PreloadPusher pushes preload link
func Preload ¶
func Preload() *PreloadPusher
Preload creates new PreloadPusher
Example ¶
Push assets driven by the upstream's own "Link: <...>; rel=preload" response headers instead of a fixed link. Each preload link is pushed as the response headers are written, except those marked with the "nopush" parameter.
package main
import (
"github.com/moonrhythm/parapet"
"github.com/moonrhythm/parapet/pkg/h2push"
)
func main() {
s := parapet.New()
s.Use(h2push.Preload())
// A downstream handler/upstream that emits e.g.
// Link: </static/app.css>; rel=preload; as=style
// Link: </static/hero.png>; rel=preload; as=image; nopush
// gets app.css pushed; hero.png is honored as nopush and skipped.
}
Output:
func (PreloadPusher) ServeHandler ¶
func (m PreloadPusher) ServeHandler(h http.Handler) http.Handler
ServeHandler implements middleware interface