http2preload

package module
v0.0.0-...-f5c2e3c Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 27, 2015 License: Apache-2.0 Imports: 7 Imported by: 2

README

http2preload

A package for manipulating HTTP/2 preload, supporting Google App Engine for Go.

See https://github.com/GoogleChrome/http2push-gae/tree/master/examples/go for a sample usage.

Docs are available on godoc.org/github.com/google/http2preload.

License

(c) Google, 2015. Licensed under Apache-2 license.

Documentation

Overview

Package http2preload provides a way to manipulate HTTP/2 preload header. See https://w3c.github.io/preload/ for Preload feature details.

Index

Constants

View Source
const (
	Audio  = "audio"
	Font   = "font"
	Image  = "image"
	Script = "script"
	Style  = "style"
	Track  = "track"
	Video  = "video"
)

Request types, as specified by https://fetch.spec.whatwg.org/#concept-request-type

Variables

This section is empty.

Functions

func AddHeader

func AddHeader(hdr http.Header, scheme, base string, assets map[string]AssetOpt)

AddHeader adds a "link" header to hdr for each assets entry, as specified in https://w3c.github.io/preload/. "scheme://base" will be prepended to a key of assets which are not prefixed with "http:" or "https:".

Types

type AssetOpt

type AssetOpt struct {
	// Type is the resource type
	Type string `json:"type,omitempty"`

	// Weight is not used in the HTTP/2 preload spec
	// but some HTTP/2 servers, while implementing stream priorities,
	// could benefit from this manifest format as well.
	Weight uint8 `json:"weight,omitempty"`
}

AssetOpt defines a single resource options.

type Manifest

type Manifest map[string]map[string]AssetOpt

Manifest is the preload manifest map where each value, being a collection of resources to be preloaded, keyed by a serving URL path which requires those resources.

func ReadManifest

func ReadManifest(name string) (Manifest, error)

ReadManifest reads a push manifest from name file. It caches the value in memory so that subsequent requests won't hit the disk again.

A manifest file can also be generated with a tool found in cmd/http2preload-manifest.

func (Manifest) Handler

func (m Manifest) Handler(f http.HandlerFunc) http.Handler

Handler creates a new handler which adds preload header(s) if in-flight request URL matches one of the m entries.

Directories

Path Synopsis
cmd
http2preload-manifest
This program generates preload manifest in JSON format.
This program generates preload manifest in JSON format.
Package generate parses HTML and extracts assets suitable for constructing http2preload.Manifest.
Package generate parses HTML and extracts assets suitable for constructing http2preload.Manifest.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL