Documentation ¶
Index ¶
- Constants
- func CORS(next webkit.Handler) webkit.Handler
- func Gzip(next webkit.Handler) webkit.Handler
- func Logger(next webkit.Handler) webkit.Handler
- func NonWWWRedirect(next webkit.Handler) webkit.Handler
- func Recover(next webkit.Handler) webkit.Handler
- func RequestID(next webkit.Handler) webkit.Handler
- func TrailingSlashRedirect(next webkit.Handler) webkit.Handler
- func WWWRedirect(next webkit.Handler) webkit.Handler
Constants ¶
const ( // RequestIDHeader is the name of the HTTP Header which contains the request id. // Exported so that it can be changed by developers RequestIDHeader = "X-Request-ID" // RequestIDContextKey is the key used to define a unique // identifier within echo context. RequestIDContextKey = "request_id" )
Variables ¶
This section is empty.
Functions ¶
func CORS ¶
CORS returns a Cross-Origin Resource Sharing (CORS) middleware. See also MDN: Cross-Origin Resource Sharing (CORS).
Security: Poorly configured CORS can compromise security because it allows relaxation of the browser's Same-Origin policy. See Exploiting CORS misconfigurations for Bitcoins and bounties and Portswigger: Cross-origin resource sharing (CORS) for more details.
func Gzip ¶
Gzip returns a middleware that compresses HTTP responses using gzip compression. It wraps the provided handler, adding gzip compression to responses based on the specified configuration.
func Logger ¶
Logger is a middleware that logs the start and end of each request, along with some useful data about what was requested, what the response status was, and how long it took to return. When standard output is a TTY, Logger will print in color, otherwise it will print in black and white. Logger prints a request ID if one is provided.
IMPORTANT NOTE: Logger should go before any other middleware that may change the response, such as middleware.Recover. Example:
app := webkit.New() app.Plug(middleware.Logger) // <--<< Logger should come before Recover app.Plug(middleware.Recover) r.Get("/", handler)
func NonWWWRedirect ¶
NonWWWRedirect redirects all requests to the non-www subdomain of the current host. Redirects are performed using a 301 status code (Permanent Redirect) using HTTPS.
For example, a request to "https://www.example.com" will be redirected to "https://example.com".
func Recover ¶
Recover is a middleware that recovers from panics, logs the panic (and a backtrace), and returns a HTTP 500 (Internal Server Error) status if possible. The error is also reported to Sentry.
This middleware should be plugged in first to ensure that it catches any panics that occur in the request-response cycle.
func RequestID ¶
RequestID assigns a unique identifier to the contact under RequestIDContextKey. The ID is also sent back in the payload to the calling client.
func TrailingSlashRedirect ¶
TrailingSlashRedirect is a middleware that will match request paths with a trailing slash and redirect to the same path, less the trailing slash.
NOTE: RedirectSlashes middleware is *incompatible* with http.FileServer.
func WWWRedirect ¶
WWWRedirect redirects all requests to the www subdomain of the current host. Redirects are performed using a 301 status code (Permanent Redirect) using HTTPS.
For example, a request to "https://example.com" will be redirected to "https://www.example.com".
Types ¶
This section is empty.