Documentation
¶
Index ¶
- Variables
- func CURL(req *http.Request, reqBody string) string
- func HandleBrotli(next http.Handler) http.Handler
- func HandleHTMLMinification() func(http.Handler) http.Handler
- func HandleHTTPMethodConversion(next http.Handler) http.Handler
- func InjectUserContext(next http.Handler, uid string, username string) http.Handler
- func InjectWorkerPoolIntoContext(next http.Handler, workerPool pond.Pool) http.Handler
- func RequestLogger(logger *log.Logger, o *Options) func(http.Handler) http.Handler
- func SetAttrs(ctx context.Context, attrs ...string)
- func SetError(ctx context.Context, err error) error
- type Options
Constants ¶
This section is empty.
Variables ¶
var ErrClientAborted = fmt.Errorf("request aborted: client disconnected before response was sent")
Functions ¶
func HandleHTMLMinification ¶
HandleHTMLMinification returns a chi middleware that minifies HTML responses
func HandleHTTPMethodConversion ¶
handleHTTPMethodConversion is a middleware component that checks for the combination of a POST method with a form field named _method having a value of PUT. POST method with a form field named _method having a value of DELETE. It converts the request method to PUT or DELETE accordingly. This middleware should be used before any handlers that require PUT or DELETE methods to function correctly. It is typically used in web applications that need to support RESTful operations via HTML forms. It is designed to be used with the Chi router, but can be adapted for other routers It should run early in the middleware stack.
func InjectUserContext ¶ added in v1.20.0
func InjectWorkerPoolIntoContext ¶ added in v1.20.0
func RequestLogger ¶ added in v1.21.0
Types ¶
type Options ¶ added in v1.21.0
type Options struct {
// RecoverPanics recovers from panics occurring in the underlying HTTP handlers
// and middlewares and returns HTTP 500 unless response status was already set.
//
// NOTE: Panics are logged as errors automatically, regardless of this setting.
RecoverPanics bool
// Skip is an optional predicate function that determines whether to skip
// recording logs for a given request.
//
// If nil, all requests are recorded.
// If provided, requests where Skip returns true will not be recorded.
Skip func(req *http.Request, respStatus int) bool
// LogRequestHeaders is a list of headers to be logged.
// If not provided, the default is ["Content-Type", "Origin"].
//
// WARNING: Do not leak any request headers with sensitive information.
LogRequestHeaders []string
// LogRequestBody is an optional predicate function that controls logging of request body.
//
// If the function returns true, the request body will be logged.
// If false, no request body will be logged.
//
// WARNING: Do not leak any request bodies with sensitive information.
LogRequestBody func(req *http.Request) bool
// LogResponseHeaders controls a list of headers to be logged.
//
// If not provided, there are no default headers.
LogResponseHeaders []string
// LogResponseBody is an optional predicate function that controls logging of response body.
//
// If the function returns true, the response body will be logged.
// If false, no response body will be logged.
//
// WARNING: Do not leak any response bodies with sensitive information.
LogResponseBody func(req *http.Request) bool
// LogBodyContentTypes defines a list of body Content-Types that are safe to be logged
// with LogRequestBody or LogResponseBody options.
//
// If not provided, the default is ["application/json", "application/xml", "text/plain", "text/csv", "application/x-www-form-urlencoded", ""].
LogBodyContentTypes []string
// LogBodyMaxLen defines the maximum length of the body to be logged.
//
// If not provided, the default is 1024 bytes. Set to -1 to log the full body.
LogBodyMaxLen int
// LogExtraAttrs is an optional function that lets you add extra string attributes
// to the request log.
//
// WARNING: Be careful not to leak any sensitive information in the logs.
LogExtraAttrs func(req *http.Request, reqBody string, respStatus int) []string
}