Documentation
¶
Index ¶
- func AddContextValue(key, value any, next http.Handler) http.Handler
- func AddRequestID(next http.Handler) http.Handler
- func NoCache(next http.Handler) http.Handler
- func RealIP(next http.Handler) http.Handler
- func RedirectHTTPS(next http.Handler) http.Handler
- func RemoveTrailingSlash(next http.Handler) http.Handler
- func Wrap(h http.Handler, wrap ...Wrapper) http.Handler
- type Middleware
- type Wrapper
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AddContextValue ¶ added in v0.6.0
func AddRequestID ¶ added in v0.6.3
AddRequestID middleware reads the request id from the "X-Request-ID" header or generates a random id, and adds this to the http.Request's context values using serv.AddRequestID.
func NoCache ¶ added in v0.6.0
NoCache adds middleware that sets headers to prevent caching of the response, using response.NoCache.
func RealIP ¶ added in v0.6.0
RealIP is a middleware that sets a http.Request's RemoteAddr to the results of parsing either "X-Forwarded-For" header(s) or the "X-Real-Ip" header (in that order).
This middleware should be inserted fairly early in the middleware stack to ensure that subsequent layers (e.g., request loggers) which examine the RemoteAddr will see the intended value.
You should only use this middleware if you can trust the headers passed to you (in particular, the two headers this middleware uses), for example because you have placed a reverse proxy like HAProxy or nginx in front of the server. If your reverse proxies are configured to pass along arbitrary header values from the client, or if you use this middleware without a reverse proxy, malicious clients will be able to make you very sad (or, depending on how you're using RemoteAddr, vulnerable to an attack of some sort).
This function is based on the RealIP middleware from the Goji web framework.
func RedirectHTTPS ¶ added in v0.6.0
RedirectHTTPS adds middleware that redirects any http request to its https equivalent url, using http.Redirect. It uses the redirect code http.StatusMovedPermanently for any GET request and http.StatusTemporaryRedirect for any other method.
func RemoveTrailingSlash ¶
RemoveTrailingSlash adds middleware that redirects any request which has a trailing slash to the equivalent path without trailing slash, using http.Redirect. It uses the redirect code http.StatusMovedPermanently for any GET request and http.StatusTemporaryRedirect for any other method.
Types ¶
type Middleware ¶
type Middleware []Wrapper
Middleware consists of multiple [Wrapper]s which can be wrapped around a http.Handler using Wrap.