Documentation ¶
Index ¶
- Variables
- func AcceptedEncodings(directiveQValues string) []string
- func Chevroned(raw string, suffix string) string
- func Compressed(w io.Writer, encoding string) (io.WriteCloser, error)
- func DefinitelyUncompressable(mimetype string) bool
- func NopWriteCloser(w io.Writer) io.WriteCloser
- func OrderByQValues(directiveQValues string, expand func(directive string) []string) []string
- func Plain(w http.ResponseWriter, r *http.Request, code int) int
- func PlainBody(w http.ResponseWriter, r *http.Request, code int) int
- func Plainf(w http.ResponseWriter, code int, format string, a ...any) int
- type FileServer
- func (fsrv *FileServer) Canonicalize(name string) (string, bool)
- func (fsrv *FileServer) IsDir(path string) (isdir bool, ok bool)
- func (fsrv *FileServer) IsExcluded(path string) bool
- func (fsrv *FileServer) Open(path string) (fs.File, error)
- func (fsrv *FileServer) Retrieve(req request) representation
- func (fsrv *FileServer) ServeHTTP(w http.ResponseWriter, r *http.Request)
- func (fsrv *FileServer) SetExtraHeaders(path string, headers map[string][]string)
- type Range
Constants ¶
This section is empty.
Variables ¶
var ErrNoUnderlyingFilesystem = errors.New("webutils: file server: no underlying filesystem")
var RenamedContentEncodings = map[string]string{
"x-compress": "compress",
"x-gzip": "gzip",
}
var SupportedContentEncodings = []string{
"br",
"gzip",
"compress",
"deflate",
"identity",
}
see: https://www.iana.org/assignments/http-parameters/http-parameters.xml#http-parameters-1
Functions ¶
func Chevroned ¶
Used for e.g. escaping `Link: <...>` HTTP headers. Inspired by net/http's Redirect implementation. Ref. https://cs.opensource.google/go/go/+/refs/tags/go1.19.2:src/net/http/http.go;drc=cbd931c9c2705e0e3a44c3b299ac2bd3369f5eb5;l=76 [accessed 2022-10-05]
func DefinitelyUncompressable ¶
DefinitelyUncompressable returns if the given MIME type is known to employ compression itself, making transfer compression unlikely to be beneficial.
func NopWriteCloser ¶
func NopWriteCloser(w io.Writer) io.WriteCloser
func OrderByQValues ¶
Types ¶
type FileServer ¶
type FileServer struct { // Underlying is the file server's underlying file source. // Underlying may be nil. // Underlying MUST support concurrent Open calls. Returned files MUST // support inter-concurrent operations but are themselves accessed // sequentially. Underlying fs.FS // Is the Underlying filesystem static? // In this case, data is permanently cached in memory after first access // alongside all accepted encodings and a cryptographic hash. UnderlyingStatic bool // When non-zero, serve this path's page when the requested page was // not found. The 404 page's path cannot be served with a status code // of 200. If the 404 page's path does not exist, a default 404 is sent. // For an HTML page, it is recommended to employ `<base>` since the page // URL path and file path are decoupled. Page404 string // Allow hidden paths (i.e. paths containing "/.") to reach Underlying.Open. AllowHidden bool // Do not send any statistics. Currently, this only includes compression // statistics. // [2022-10-05] TODO Add timing statistics (cf. `Server-Timing` HTTP header). DisableStatistics bool // When non-zero, a `Link: <...>; rel="canonical"` header is sent on // requests to canonical paths present in Underlying. // It should not contain a trailing slash or schema; "https://" is presumed. // Sample Value: "www.example.com" CanonicalHost string // Only takes effect when UnderlyingStatic is true. // When non-zero, emit a `Cache-Control: public, maxage=...` header. CacheControlMaxAge time.Duration // Do not try to deduce a `Content-Type` header; probably because one // has been already set as an extra header. ProhibitMimeTypeSniffing bool ExtraHeaders map[string][]string // contains filtered or unexported fields }
func FileServerEmbedded ¶
func FileServerEmbedded(fsys embed.FS, dir string) *FileServer
func (*FileServer) Canonicalize ¶
func (fsrv *FileServer) Canonicalize(name string) (string, bool)
Canonicalize computes a canonical name for a ressource. An HTML index file represents its parent directory; directories are marked with a trailing slash. If it no canonical name exists, name is returned unaltered.
func (*FileServer) IsDir ¶
func (fsrv *FileServer) IsDir(path string) (isdir bool, ok bool)
func (*FileServer) IsExcluded ¶
func (fsrv *FileServer) IsExcluded(path string) bool
func (*FileServer) Retrieve ¶
func (fsrv *FileServer) Retrieve(req request) representation
func (*FileServer) ServeHTTP ¶
func (fsrv *FileServer) ServeHTTP(w http.ResponseWriter, r *http.Request)
func (*FileServer) SetExtraHeaders ¶
func (fsrv *FileServer) SetExtraHeaders(path string, headers map[string][]string)