package httpsnoop

Import Path
	github.com/felixge/httpsnoop (on go.dev)

Dependency Relation
	imports 5 packages, and imported by one package

Involved Source Files capture_metrics.go Package httpsnoop provides an easy way to capture http related metrics (i.e. response time, bytes written, and http status code) from your application's http.Handlers. Doing this requires non-trivial wrapping of the http.ResponseWriter interface, which is also exposed for users interested in a more low-level API. wrap_generated.go
Package-Level Type Names (total 532, in which 16 are exported)
/* sort exporteds by: | */
CloseNotifyFunc is part of the http.CloseNotifier interface.
EnableFullDuplexFunc is part of the fullDuplexEnabler interface.
FlushErrorFunc is part of the httpFlushError interface.
FlushFunc is part of the http.Flusher interface.
HeaderFunc is part of the http.ResponseWriter interface.
HijackFunc is part of the http.Hijacker interface.
Hooks defines a set of method interceptors for methods included in http.ResponseWriter as well as some others. You can think of them as middleware for the function calls they target. See Wrap for more details. For each method, the exact matching hook takes precedence. For example, WriteString calls the WriteString hook when it is configured, even if a Write hook is also configured. If the exact hook is not configured, most methods call through to the underlying ResponseWriter directly. Two compatibility fallbacks preserve the behavior users had before Wrap learned about newer optional interfaces: - If the underlying ResponseWriter implements io.StringWriter and WriteString is called, but only the Write hook is configured, WriteString is routed through the Write hook with []byte(s). If neither hook is configured, WriteString calls the underlying WriteString method directly. - If the underlying ResponseWriter implements both http.Flusher and FlushError, and FlushError is called, but only the Flush hook is configured, FlushError is routed through the Flush hook while preserving the error returned by the underlying FlushError method. If neither hook is configured, FlushError calls the underlying FlushError method directly. CloseNotify func(CloseNotifyFunc) CloseNotifyFunc EnableFullDuplex func(EnableFullDuplexFunc) EnableFullDuplexFunc Flush func(FlushFunc) FlushFunc FlushError func(FlushErrorFunc) FlushErrorFunc Header func(HeaderFunc) HeaderFunc Hijack func(HijackFunc) HijackFunc Push func(PushFunc) PushFunc ReadFrom func(ReadFromFunc) ReadFromFunc SetReadDeadline func(SetReadDeadlineFunc) SetReadDeadlineFunc SetWriteDeadline func(SetWriteDeadlineFunc) SetWriteDeadlineFunc Write func(WriteFunc) WriteFunc WriteHeader func(WriteHeaderFunc) WriteHeaderFunc WriteString func(WriteStringFunc) WriteStringFunc func Wrap(w http.ResponseWriter, hooks Hooks) http.ResponseWriter
Metrics holds metrics captured from CaptureMetrics. Code is the first http response code passed to the WriteHeader func of the ResponseWriter. If no such call is made, a default code of 200 is assumed instead. Duration is the time it took to execute the handler. Written is the number of bytes successfully written by the Write or ReadFrom function of the ResponseWriter. ResponseWriters may also write data to their underlaying connection directly (e.g. headers), but those are not tracked. Therefor the number of Written bytes will usually match the size of the response body. CaptureMetrics wraps w and calls fn with the wrapped w and updates Metrics m with the resulting metrics. This is similar to CaptureMetricsFn, but allows one to customize starting Metrics object. func CaptureMetrics(hnd http.Handler, w http.ResponseWriter, r *http.Request) Metrics func CaptureMetricsFn(w http.ResponseWriter, fn func(http.ResponseWriter)) Metrics
PushFunc is part of the http.Pusher interface.
ReadFromFunc is part of the io.ReaderFrom interface.
SetReadDeadlineFunc is part of the deadliner interface.
SetWriteDeadlineFunc is part of the deadliner interface.
( Unwrapper) Unwrap() http.ResponseWriter
WriteFunc is part of the http.ResponseWriter interface.
WriteHeaderFunc is part of the http.ResponseWriter interface.
WriteStringFunc is part of the io.StringWriter interface.
Package-Level Functions (total 4, all are exported)
CaptureMetrics wraps the given hnd, executes it with the given w and r, and returns the metrics it captured from it.
CaptureMetricsFn wraps w and calls fn with the wrapped w and returns the resulting metrics. This is very similar to CaptureMetrics (which is just sugar on top of this func), but is a more usable interface if your application doesn't use the Go http.Handler interface.
Unwrap returns the underlying http.ResponseWriter from within zero or more layers of httpsnoop wrappers.
Wrap returns a wrapped version of w that provides the exact same interface as w. Specifically if w implements any combination of: - http.Flusher - httpFlushError - http.CloseNotifier - http.Hijacker - io.ReaderFrom - deadliner - fullDuplexEnabler - http.Pusher - io.StringWriter The wrapped version will implement the exact same combination. If no hooks are set, the wrapped version also behaves exactly as w. Hooks targeting methods not supported by w are ignored. Any other hooks will intercept the method they target and may modify the call's arguments and/or return values. The CaptureMetrics implementation serves as a working example for how the hooks can be used.