static

package
v0.1.11 Latest Latest
Warning

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

Go to latest
Published: Jan 31, 2025 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetFileHash added in v0.1.6

func GetFileHash(filename string) string

GetFileHash looks for a hash as a suffix to a file (e.g, "foo-JK1llaO.js").

func GetQueryHash added in v0.1.6

func GetQueryHash(rawQuery string) string

GetQueryHash matches a complete input to whether it looks like a long-term hash.

Types

type Content

type Content interface {
	Get(path string) (*FileInfo, io.ReadCloser)
	Exists(path string) bool
}

Content controls what is rendered inside ServeFs.

type FileInfo

type FileInfo struct {
	// Any available hash from the file's contents, or CRC or something.
	ContentHash string

	// ContentType if known.
	ContentType string

	// Additional headers to include, e.g, for CSP
	Header http.Header
}

FileInfo is returned from Content.

type ServeFs

type ServeFs struct {
	Content Content

	// AddPrefix is added to all paths before being checked inside Content.
	AddPrefix string

	// Normally, no files "foo.html" are served. This allows them to be served at "foo", without a trailing slash.
	// If "foo.html" AND "foo/index.html" exist, only the latter will be served.
	ServeNakedHtml bool

	// AllowFrame controls the X-Frame-Options header.
	AllowFrame bool

	// HtmlNotFoundPath is loaded from Content if we think this is a missing page (with a trailing slash). It does not have AddPrefix applied to it.
	HtmlNotFoundPath string

	// InsertHtmlHash controls whether a short `<!--:<hash>:-->` is added to each served HTML page.
	InsertHtmlHash bool

	// UpdateHeader may be provided to update the headers of returned responses. Useful for CSP.
	UpdateHeader func(http.Header, ServeInfo)
}

ServeFs implements http.Handler.

func (*ServeFs) ServeHTTP

func (c *ServeFs) ServeHTTP(w http.ResponseWriter, r *http.Request)

type ServeInfo

type ServeInfo struct {
	FileInfo
	Is404        bool
	IsHtml       bool
	IsHead       bool
	NotModified  bool // did the client match the prior ETag
	CacheForever bool
}

ServeInfo is passed to UpdateHeader to control header generation.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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