Documentation ¶
Index ¶
- Constants
- Variables
- func DefaultClient() *http.Client
- func ServeError(res http.ResponseWriter, message string, statusCode int)
- func ServerForbiddenError(res http.ResponseWriter)
- func ServerInternalErrorPlaintext(res http.ResponseWriter, message *string)
- func WebappHandler(folder fs.FS, config *WebappHandlerConfig) (handler func(w http.ResponseWriter, r *http.Request), err error)
- type CacheRule
- type WebappHandlerConfig
Constants ¶
const ( HeaderLastModified = "Last-Modified" HeaderContentType = "Content-Type" HeaderContentEncoding = "Content-Encoding" HeaderCacheControl = "Cache-Control" HeaderContentLength = "Content-Length" HeaderConnection = "Connection" 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" HeaderContentRange = "Content-Range" HeaderReferer = "Referer" HeaderDoNotTrack = "Dnt" HeaderRange = "Range" HeaderAcceptLanguage = "Accept-Language" HeaderAcceptRanges = "Accept-Ranges" )
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
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" )
const (
AcceptRangesBytes = "bytes"
)
const (
CacheControl30SecondsCdnOnly = "public, max-age=0, s-max-age=30, must-revalidate"
)
Variables ¶
var ErrDir = errors.New("path is a folder")
var ErrInternalError = errors.New("Internal Server Error")
var ErrInvalidPath = errors.New("path is not valid")
Functions ¶
func DefaultClient ¶
DefaultClient returns an HTTP client with sane defaults
func ServeError ¶
func ServeError(res http.ResponseWriter, message string, statusCode int)
func ServerForbiddenError ¶
func ServerForbiddenError(res http.ResponseWriter)
TODO: Do we force close the TCP connection? https://stackoverflow.com/questions/72368886/is-there-a-way-to-drop-an-http-connection-in-golang-without-sending-anything-to https://www.bentasker.co.uk/posts/blog/software-development/golang-net-http-net-http-2-does-not-reliably-close-failed-connections-allowing-attempted-reuse.html
func ServerInternalErrorPlaintext ¶
func ServerInternalErrorPlaintext(res 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 ¶
Source Files ¶
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/ |