httpx

package
v0.0.0-...-0941746 Latest Latest
Warning

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

Go to latest
Published: Feb 18, 2024 License: AGPL-3.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	HeaderLastModified            = "Last-Modified"
	HeaderContentType             = "Content-Type"
	HeaderContentEncoding         = "Content-Encoding"
	HeaderCacheControl            = "Cache-Control"
	HeaderContentLength           = "Content-Length"
	HeaderETag                    = "ETag"
	HeaderServer                  = "Server"
	HeaderIfModifiedSince         = "If-Modified-Since"
	HeaderExpires                 = "Expires"
	HeaderIfNoneMatch             = "If-None-Match"
	HeaderAccept                  = "Accept"
	HeaderUserAgent               = "User-Agent"
	HeaderAuthorization           = "Authorization"
	HeaderAltSvc                  = "Alt-Svc"
	HeaderStrictTransportSecurity = "Strict-Transport-Security"
	HeaderContentDisposition      = "Content-Disposition"
	HeaderReferer                 = "Referer"
	HeaderDoNotTrack              = "Dnt"
	HeaderAcceptLanguage          = "Accept-Language"
)
View Source
const (
	CacheControlNoCache = "private, no-cache, no-store, must-revalidate" // "no-cache, no-store, no-transform, must-revalidate, private, max-age=0"
	CacheControlDynamic = "public, no-cache, must-revalidate"            // TODO https://web.dev/http-cache/, https://web.dev/love-your-cache/
	// CacheControlDynamic    = "max-age=0, must-revalidate, public" // TODO https://web.dev/http-cache/, https://web.dev/love-your-cache/
	// CacheControlNoCache       = "no-cache, no-store, no-transform, must-revalidate" // "no-cache, no-store, no-transform, must-revalidate, private, max-age=0"
	CacheControl30Seconds = "public, max-age=30, must-revalidate"
	CacheControl1Minute   = "public, max-age=60, must-revalidate"
	CacheControl5Minutes  = "public, max-age=300, stale-while-revalidate=30"
	CacheControl10Minutes = "public, max-age=600, stale-while-revalidate=60"
	CacheControl15Minutes = "public, max-age=900, stale-while-revalidate=90"
	CacheControl30Minutes = "public, max-age=1800, stale-while-revalidate=180"
	CacheControl1Hour     = "public, max-age=3600, stale-while-revalidate=360"
	CacheControl1Day      = "public, max-age=86400, stale-while-revalidate=600"
	CacheControl1Week     = "public, max-age=604800, stale-while-revalidate=600"
	CacheControl1Month    = "public, max-age=2592000, stale-while-revalidate=600"
	CacheControlImmutable = "public, max-age=31536000, immutable"
)

https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cache-Control https://developer.mozilla.org/en-US/docs/Web/HTTP/Caching

View Source
const (
	MediaTypeText = "text/plain"
	MediaTypeXml  = "application/xml"
	MediaTypeJson = "application/json"

	MediaTypeHtmlUtf8 = "text/html; charset=utf-8"
	MediaTypeTextUtf8 = "text/plain; charset=utf-8"

	MediaTypeJsonFeed = "application/feed+json"
	MediaTypeRSS      = "application/rss+xml"
	MediaTypeAtom     = "application/atom+xml"

	MediaTypeAudio = "audio"
	MediaTypeVideo = "video"
	MediaTypePNG   = "image/png"
	MediaTypeJPEG  = "image/jpeg"
	MediaTypeSVG   = "image/svg+xml"

	// https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types/Common_types
	// alternative value from the 'file' command line program: text/x-shellscript
	MediaTypeShellScript = "application/x-sh"
)
View Source
const (
	CacheControl30SecondsCdnOnly = "public, max-age=0, s-max-age=30, must-revalidate"
)

Variables

View Source
var ErrDir = errors.New("path is a folder")
View Source
var ErrInternalError = errors.New("Internal Server Error")
View Source
var ErrInvalidPath = errors.New("path is not valid")

Functions

func DefaultClient

func DefaultClient() *http.Client

DefaultClient returns an HTTP client with sane defaults

func ServerInternalErrorPlaintext

func ServerInternalErrorPlaintext(w http.ResponseWriter, message *string)

func WebappHandler

func WebappHandler(folder fs.FS, config *WebappHandlerConfig) (handler func(w http.ResponseWriter, r *http.Request), err error)

WebappHandler is an http.Handler that is designed to efficiently serve Single Page Applications. if a file is not found, it will return notFoundFile (default: index.html) with the stauscode statusNotFound WebappHandler sets the correct ETag header and cache the hash of files so that repeated requests to files return only StatusNotModified responses WebappHandler returns StatusMethodNotAllowed if the method is different than GET or HEAD

Types

type CacheRule

type CacheRule struct {
	Regexp string

	CacheControl string
	// contains filtered or unexported fields
}

type WebappHandlerConfig

type WebappHandlerConfig struct {
	// default: index.html
	NotFoundFile string
	// default: 200
	NotFoundStatus int
	// default: public, no-cache, must-revalidate
	NotFoundCacheControl string
	// default: ".js", ".css", ".woff", ".woff2"
	Cache []CacheRule
}

Directories

Path Synopsis
Package cors is net/http handler to handle CORS related requests as defined by http://www.w3.org/TR/cors/
Package cors is net/http handler to handle CORS related requests as defined by http://www.w3.org/TR/cors/

Jump to

Keyboard shortcuts

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