Documentation
¶
Overview ¶
Package mware contains HTTP middlewares.
See e.g. chi for some additional middlewares.
Index ¶
- Variables
- func Delay(d time.Duration) func(http.Handler) http.Handler
- func Headers(h http.Header) func(next http.Handler) http.Handler
- func NoCache() func(http.Handler) http.Handler
- func NoStore() func(http.Handler) http.Handler
- func RealIP(never ...string) func(http.Handler) http.Handler
- func RequestLog(opt *RequestLogOptions, printer RequestLogPrinter, ignore ...string) func(http.Handler) http.Handler
- func Unpanic(filterStack ...string) func(http.Handler) http.Handler
- func With(handler http.Handler, wares ...func(http.Handler) http.Handler) http.Handler
- func WrapWriter() func(http.Handler) http.Handler
- type RequestLogOptions
- type RequestLogPrinter
Constants ¶
This section is empty.
Variables ¶
var DefaultHeaders = http.Header{ "Strict-Transport-Security": []string{"max-age=7776000"}, "X-Frame-Options": []string{"deny"}, "X-Content-Type-Options": []string{"nosniff"}, }
DefaultHeaders will be set by default.
Functions ¶
func Delay ¶
Delay adds a delay before every request.
The default delay is taken from the paramters (which may be 0), and can also be overriden by setting a "debug-delay" cookie, which is in seconds.
This is intended for debugging frontend timing issues.
func Headers ¶
Headers sets the given headers.
DefaultHeaders will always be set. Headers passed to this function overrides them. Use a nil value to remove a header.
func NoCache ¶
NoCache sets the Cache-Control header to "no-cache".
Browsers will always validate a cache (with e.g. If-Match or If-None-Match). It does NOT tell browsers to never store a cache (use NoStore for that).
func NoStore ¶
NoStore sets the Cache-Control header to "no-store, no-cache"
Browsers will never store a local copy (the no-cache is there to be sure previously stored copies from before this header are revalidated).
func RealIP ¶
RealIP sets the RemoteAddr to CF-Connecting-IP, Fly-Client-IP, X-Azure-SocketIP, X-Real-IP, X-Forwarded-For, or the RemoteAddr without a port.
The end result willl never have a source port set. It will ignore local and private addresses such as 127.0.0.1, 192.168.1.1, etc.
TODO: allow configuring which headers to look at, as this is very much dependent on the specific configuration; preferring e.g. Fly-Client-Ip means its trivial to spoof the "real IP".
func RequestLog ¶
func RequestLog(opt *RequestLogOptions, printer RequestLogPrinter, ignore ...string) func(http.Handler) http.Handler
RequestLog logs all requests to stdout.
Any paths matching ignore will not be printed.