httpevents

package
v2.6.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 18, 2024 License: MIT Imports: 10 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultLogSanitizer = NewLogSanitizer()

Functions

func NewHandler

func NewHandler(handler http.Handler) http.Handler

NewHandler wraps the HTTP handler and returns a new handler which logs all 4xx and 5xx requests with the default logger. All other requests will only be logged in debug mode. See NewHandlerWithSanitizer for more details.

func NewHandlerWith

func NewHandlerWith(logger *events.Logger, handler http.Handler) http.Handler

NewHandlerWith wraps the HTTP handler and returns a new handler which logs all requests with logger. See NewHandlerWithSanitizer for more details.

func NewHandlerWithSanitizer added in v2.5.2

func NewHandlerWithSanitizer(sanitizer LogSanitizer, logger *events.Logger, handler http.Handler) http.Handler

NewHandlerWithSanitizer wraps the HTTP handler and returns a new handler which logs all requests with logger. The LogSanitizer is used to sanitize the request and response that is logged. eg, to remove PII.

Panics from handler are intercepted and trigger a 500 response if no response header was sent yet. The panic is not silenced tho and is propagated to the parent handler.

func NewTransport

func NewTransport(roundTripper http.RoundTripper) http.RoundTripper

NewTransport wraps roundTripper and returns a new transport which logs all submitted requests with the default logger.

func NewTransportWith

func NewTransportWith(logger *events.Logger, roundTripper http.RoundTripper) http.RoundTripper

NewTransportWith wraps roundTripper and returns a new transport which logs all submitted requests with logger.

Types

type HeaderSanitizer added in v2.5.2

type HeaderSanitizer func(http.Header) http.Header

HeaderSanitizer is a function that sanitizes a header

var DefaultHeaderSanitizer HeaderSanitizer = func(h http.Header) http.Header {
	return h
}

type LogSanitizer added in v2.5.2

type LogSanitizer struct {
	Path  PathSanitizer
	Query QuerySanitizer
	// contains filtered or unexported fields
}

func NewLogSanitizer added in v2.5.2

func NewLogSanitizer() LogSanitizer

func (LogSanitizer) ReqHeaders added in v2.5.2

func (l LogSanitizer) ReqHeaders(h http.Header) http.Header

ReqHeaders makes a copy of the request headers and sanitizes the resulting headers

func (LogSanitizer) ResHeaders added in v2.5.2

func (l LogSanitizer) ResHeaders(h http.Header) http.Header

ResHeaders makes a copy of the response headers and sanitizes the resulting headers

func (LogSanitizer) WithPathSanitizer added in v2.5.2

func (l LogSanitizer) WithPathSanitizer(sanitizer PathSanitizer) LogSanitizer

func (LogSanitizer) WithQuerySanitizer added in v2.5.2

func (l LogSanitizer) WithQuerySanitizer(sanitizer QuerySanitizer) LogSanitizer

func (LogSanitizer) WithReqHeaderSanitizer added in v2.5.2

func (l LogSanitizer) WithReqHeaderSanitizer(sanitizer HeaderSanitizer) LogSanitizer

func (LogSanitizer) WithResHeaderSanitizer added in v2.5.2

func (l LogSanitizer) WithResHeaderSanitizer(sanitizer HeaderSanitizer) LogSanitizer

type PathSanitizer added in v2.5.2

type PathSanitizer func(string) string

PathSanitizer is a function that sanitizes a path

var DefaultPathSanitizer PathSanitizer = func(path string) string {
	return path
}

type QuerySanitizer added in v2.5.2

type QuerySanitizer func(string) string

QuerySanitizer is a function that sanitizes a query

var DefaultQuerySanitizer QuerySanitizer = func(query string) string {
	return query
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL