示例#1
0
// h2preload adds HTTP/2 preload header configured in h2config.
func h2preload(h http.Header, host, tplname string) {
	a, ok := h2config[tplname]
	if !ok {
		return
	}
	s := "https"
	if isDevServer() {
		s = "http"
	}
	http2preload.AddHeader(h, s, path.Join(host, config.Prefix), a)
}
示例#2
0
// handleGopher demonstrates how to push resources
// without a manifest file.
func handleGopher(w http.ResponseWriter, r *http.Request) {
	assets := map[string]http2preload.AssetOpt{
		gopher: {Type: http2preload.Image},
	}
	s := "http"
	if r.TLS != nil {
		s = "https"
	}
	// the next line will add the following header:
	// Link: <host/gopher.png>; rel=preload; as=image
	http2preload.AddHeader(w.Header(), s, r.Host, assets)
	// respond with minimal HTML5, omitting <html> and <body>
	fmt.Fprintf(w, `<img src="%s">`, gopher)
}