Documentation ¶
Overview ¶
Package capture is a middleware that captures requests/responses size, and status.
For another middleware to get those attributes of a request/response, this middleware should be added before in the middleware chain.
chain := alice.New(). Append(capture.Wrap). Append(myOtherMiddleware). then(...)
As this middleware stores those data in the request's context, the data can be retrieved at anytime after the ServerHTTP.
func (h *Handler) ServeHTTP(rw http.ResponseWriter, req *http.Request, next http.Handler) { capt, err := capture.FromContext(req.Context()) if err != nil { ... } fmt.Println(capt.Status()) fmt.Println(capt.ResponseSize()) fmt.Println(capt.RequestSize()) }
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Capture ¶
type Capture struct {
// contains filtered or unexported fields
}
Capture is the object populated by the capture middleware, holding probes that allow to gather information about the request and response.
func FromContext ¶
FromContext returns the Capture value found in ctx, or an empty Capture otherwise.
func (*Capture) NeedsReset ¶ added in v2.9.2
func (c *Capture) NeedsReset(rw http.ResponseWriter) bool
NeedsReset returns whether the given http.ResponseWriter is the capture's probe.
func (*Capture) RequestSize ¶
RequestSize returns the size of the request's body if it applies, zero otherwise.
func (*Capture) Reset ¶ added in v2.9.2
Reset returns a new handler that renews the Capture's probes, and inserts them when deferring to next.