Documentation ¶
Index ¶
- Variables
- func AllowAccept(contentTypes ...string) func(http.Handler) http.Handler
- func AllowContentType(contentTypes ...string) func(http.Handler) http.Handler
- func AllowHTTPHeader(badStatus int, name string, values ...string) func(http.Handler) http.Handler
- func AllowMethod(methods ...string) func(http.Handler) http.Handler
- func AllowUserAgent(userAgents ...string) func(http.Handler) http.Handler
- func CacheControl(opts ...string) func(http.Handler) http.Handler
- func Clickjacking(opt string) func(http.Handler) http.Handler
- func ContentSniffing() func(http.Handler) http.Handler
- func Context(f ContextFunc) func(http.Handler) http.Handler
- func Debug(b bool) func(http.Handler) http.Handler
- func DisallowAccept(contentTypes ...string) func(http.Handler) http.Handler
- func DisallowContentType(contentTypes ...string) func(http.Handler) http.Handler
- func DisallowHTTPHeader(badStatus int, name string, values ...string) func(http.Handler) http.Handler
- func DisallowMethod(methods ...string) func(http.Handler) http.Handler
- func DisallowUserAgent(userAgents ...string) func(http.Handler) http.Handler
- func ETag() func(http.Handler) http.Handler
- func Expires(d time.Duration) func(http.Handler) http.Handler
- func HSTS(maxAge int, opt string) func(http.Handler) http.Handler
- func NoCache() func(http.Handler) http.Handler
- func RateLimit(rl int) func(http.Handler) http.Handler
- func RateLimitPerIP(rl int) func(http.Handler) http.Handler
- func RealIP() func(http.Handler) http.Handler
- func Recover(out io.Writer) func(http.Handler) http.Handler
- func RequestHeader(fs ...HeaderFunc) func(http.Handler) http.Handler
- func ResponseHeader(fs ...HeaderFunc) func(http.Handler) http.Handler
- func Stampede(d time.Duration) func(http.Handler) http.Handler
- func Switch(f func(r *http.Request) bool, h http.Handler) func(http.Handler) http.Handler
- func Timeout(d time.Duration) func(http.Handler) http.Handler
- func Use(middlewares ...func(http.Handler) http.Handler) func(http.Handler) http.Handler
- func XSSFiltering(opt string) func(http.Handler) http.Handler
- type ContextFunc
- type HeaderFunc
- func AddHeaderFunc(key, value string) HeaderFunc
- func CacheControlHeaderFunc(opts ...string) HeaderFunc
- func ClickjackingHeaderFunc(opt string) HeaderFunc
- func ContentSniffingHeaderFunc() HeaderFunc
- func ExpiresHeaderFunc(d time.Duration) HeaderFunc
- func HSTSHeaderFunc(maxAge int, opt string) HeaderFunc
- func NoCacheHeaderFunc() HeaderFunc
- func XSSFilteringHeaderFunc(opt string) HeaderFunc
- type Metrics
- type MetricsRecorder
- type MetricsRecorderOption
- type RequestMetrics
Constants ¶
This section is empty.
Variables ¶
var HoneypotUserAgents = []string{
"0xSCANNER",
"20010801",
"AhrefsBot",
"Alprazolam",
"BLEXBot",
"BOT for JCE",
"Baiduspider",
"Gecko/20100115",
"Gemini",
"Hakai",
"Hello",
"Indy Library",
"Indy-Library",
"JDatabaseDriverMysqli",
"Jorgee",
"LMAO",
"MJ12bot",
"Mappy",
"Morfeus",
"NYU",
"Nessus",
"Nikto",
"OpenVAS",
"Ronin",
"SemrushBot",
"Shinka",
"WPScan",
"ZmEu",
"aiohttp",
"masscan",
"muhstik",
"sqlmap",
"sysscan",
"union select",
"yandex",
"zgrab",
}
HoneypotUserAgents ...
Functions ¶
func AllowAccept ¶ added in v0.4.0
AllowAccept is middleware that allows a request only if any of the specified strings is included in the Accept header. Returns 406 Not Acceptable status if the request has a type that is not allowed.
func AllowContentType ¶ added in v0.2.0
AllowContentType is middleware that allows a request only if any of the specified strings is included in the Content-Type header. Returns 415 Unsupported Media Type status if the request has a type that is not allowed.
func AllowHTTPHeader ¶
AllowHTTPHeader is middleware that allows a request only when one of the specified strings is included in the specified request header.
func AllowMethod ¶ added in v0.3.0
AllowMethod is a middleware that returns a 405 Method Not Allowed status if the request method is not one of the given methods.
func AllowUserAgent ¶
AllowUserAgent is middleware that allows a request only if any of the specified strings is included in the User-Agent header. Returns 403 Forbidden status if the request has a user-agent that is not allowed.
func CacheControl ¶ added in v0.3.0
CacheControl adds the Cache-Control header.
func Clickjacking ¶ added in v0.2.0
Clickjacking mitigates clickjacking attacks by limiting the display of iframe.
func ContentSniffing ¶ added in v0.2.0
ContentSniffing adds a header for Content-Type sniffing vulnerability countermeasures.
func Context ¶
func Context(f ContextFunc) func(http.Handler) http.Handler
Context is middleware that edits the context of the request.
func Debug ¶ added in v0.9.0
Debug provides middleware that executes the handler only if b is true. If b is false, it will return 404.
func DisallowAccept ¶ added in v0.4.0
DisallowAccept is middleware that disallow a request only if any of the specified strings is included in the Accept header. Returns 406 Not Acceptable status if the request has a type that is not allowed.
func DisallowContentType ¶ added in v0.2.0
DisallowContentType is middleware that disallow a request only if any of the specified strings is included in the Content-Type header. Returns 415 Unsupported Media Type status if the request has a type that is not allowed.
func DisallowHTTPHeader ¶
func DisallowHTTPHeader(badStatus int, name string, values ...string) func(http.Handler) http.Handler
DisallowHTTPHeader is middleware that disallows a request only when one of the specified strings is included in the specified request header.
func DisallowMethod ¶ added in v0.3.0
DisallowMethod is a middleware that returns a 405 Method Not Allowed status if the request method is one of the given methods.
func DisallowUserAgent ¶
DisallowUserAgent is middleware that disallow a request only if any of the specified strings is included in the User-Agent header. Returns 403 Forbidden status if the request has a user-agent that is not allowed.
func ETag ¶ added in v0.10.0
ETag provides middleware that calculates MD5 from the response data and sets it in the ETag header.
func Expires ¶ added in v0.10.0
Expires provides middleware for adding response expiration dates. The expiration time is set to the current time plus d.
func HSTS ¶ added in v0.2.0
HSTS adds the Strict-Transport-Security header. Proper use of this header will mitigate stripping attacks.
func RateLimit ¶ added in v0.8.0
RateLimit provides middleware that limits the number of requests processed per second.
func RateLimitPerIP ¶ added in v0.8.0
RateLimitPerIP provides middleware that limits the number of requests processed per second per IP.
func RealIP ¶ added in v0.3.0
RealIP is middleware that overwrites RemoteAddr of http.Request with X-Forwarded-For or X-Real-IP header. Validation of the X-Forwarded-For header is done from right to left.
func Recover ¶ added in v0.3.0
Recover is a middleware that recovers from panic and records a stack trace and returns a 500 Internal Server Error status.
func RequestHeader ¶ added in v0.2.0
func RequestHeader(fs ...HeaderFunc) func(http.Handler) http.Handler
RequestHeader is middleware that edits the header of the request.
func ResponseHeader ¶ added in v0.2.0
func ResponseHeader(fs ...HeaderFunc) func(http.Handler) http.Handler
ResponseHeader is middleware that edits the header of the response.
func Stampede ¶ added in v0.5.0
Stampede provides a simple cache middleware that is valid for a specified amount of time. It uses singleflight for caching to prevent thundering-herd and cache-stampede. If this middleware is requested at the same time, it executes the handler only once and shares the execution result with all requests.
func Switch ¶ added in v0.10.0
Switch provides a middleware that executes the next handler if the result of f is true, and executes h if it is false.
func Timeout ¶ added in v0.2.0
Timeout cancels the context at the given time. Returns 504 Gateway Timeout status if a timeout occurs.
Types ¶
type HeaderFunc ¶ added in v0.2.0
HeaderFunc ...
func AddHeaderFunc ¶ added in v0.11.0
func AddHeaderFunc(key, value string) HeaderFunc
AddHeaderFunc adds the key, value pair to the header.
func CacheControlHeaderFunc ¶ added in v0.3.0
func CacheControlHeaderFunc(opts ...string) HeaderFunc
CacheControlHeaderFunc returns a HeaderFunc that adds a Cache-Control header.
func ClickjackingHeaderFunc ¶ added in v0.2.0
func ClickjackingHeaderFunc(opt string) HeaderFunc
ClickjackingHeaderFunc returns a HeaderFunc to mitigate a clickjacking vulnerability.
func ContentSniffingHeaderFunc ¶ added in v0.2.0
func ContentSniffingHeaderFunc() HeaderFunc
ContentSniffingHeaderFunc returns a HeaderFunc for Content-Type sniffing vulnerability countermeasure.
func ExpiresHeaderFunc ¶ added in v0.10.0
func ExpiresHeaderFunc(d time.Duration) HeaderFunc
ExpiresHeaderFunc returns a HeaderFunc that adds an expiration date. The expiration time is set to the current time plus d.
func HSTSHeaderFunc ¶ added in v0.2.0
func HSTSHeaderFunc(maxAge int, opt string) HeaderFunc
HSTSHeaderFunc returns a HeaderFunc that adds a Strict-Transport-Security header.
func NoCacheHeaderFunc ¶ added in v0.3.0
func NoCacheHeaderFunc() HeaderFunc
NoCacheHeaderFunc returns the HeaderFunc to add the Cache-Control header that disables the cache.
func XSSFilteringHeaderFunc ¶ added in v0.10.0
func XSSFilteringHeaderFunc(opt string) HeaderFunc
XSSFilteringHeaderFunc returns a HeaderFunc to enable XSS filtering.
type Metrics ¶ added in v0.6.0
type Metrics struct { UptimeDurationNanoseconds int64 `json:"uptimeDurationNanoseconds"` UptimeDurationMilliseconds int64 `json:"uptimeDurationMilliseconds"` GoroutinesTotalCount int64 `json:"goroutinesTotalCount"` MaxGoroutinesCount int64 `json:"maxGoroutinesCount"` MinGoroutinesCount int64 `json:"minGoroutinesCount"` AvgGoroutinesCount int64 `json:"avgGoroutinesCount"` RequestsTotalCount int64 `json:"requestsTotalCount"` TotalRequestDurationNanoseconds int64 `json:"totalRequestDurationNanoseconds"` MaxRequestDurationNanoseconds int64 `json:"maxRequestDurationNanoseconds"` MinRequestDurationNanoseconds int64 `json:"minRequestDurationNanoseconds"` AvgRequestDurationNanoseconds int64 `json:"avgRequestDurationNanoseconds"` TotalRequestDurationMilliseconds int64 `json:"totalRequestDurationMilliseconds"` MaxRequestDurationMilliseconds int64 `json:"maxRequestDurationMilliseconds"` MinRequestDurationMilliseconds int64 `json:"minRequestDurationMilliseconds"` AvgRequestDurationMilliseconds int64 `json:"avgRequestDurationMilliseconds"` MaxRequestBytesCount int64 `json:"maxRequestBytesCount"` MinRequestBytesCount int64 `json:"minRequestBytesCount"` MaxResponseBytesCount int64 `json:"maxResponseBytesCount"` MinResponseBytesCount int64 `json:"minResponseBytesCount"` MethodCount map[string]int64 `json:"methodCount"` StatusCount map[int]int64 `json:"statusCount"` StatusClassCount map[string]int64 `json:"statusClassCount"` }
Metrics ...
type MetricsRecorder ¶ added in v0.6.0
type MetricsRecorder struct {
// contains filtered or unexported fields
}
MetricsRecorder provides features for recording and retrieving metrics.
func NewMetricsRecorder ¶ added in v0.6.0
func NewMetricsRecorder(opts ...MetricsRecorderOption) *MetricsRecorder
NewMetricsRecorder creates and returns a new MetricsRecorder.
func (*MetricsRecorder) Handler ¶ added in v0.6.0
func (mr *MetricsRecorder) Handler(w http.ResponseWriter, r *http.Request)
Handler returns metrics in JSON.
func (*MetricsRecorder) Metrics ¶ added in v0.6.0
func (mr *MetricsRecorder) Metrics() *Metrics
Metrics ...
func (*MetricsRecorder) Middleware ¶ added in v0.6.0
func (mr *MetricsRecorder) Middleware() func(http.Handler) http.Handler
Middleware records metrics. If an error occurs, call the next handler without recording any metrics.
type MetricsRecorderOption ¶ added in v0.7.0
type MetricsRecorderOption func(mr *MetricsRecorder)
MetricsRecorderOption ...
func WithRequestMetricsHookFunc ¶ added in v0.7.0
func WithRequestMetricsHookFunc(fn func(*RequestMetrics)) MetricsRecorderOption
WithRequestMetricsHookFunc sets the hook function to be called for each request. The hook function receives the request metrics as an argument.
type RequestMetrics ¶ added in v0.7.0
type RequestMetrics struct { StartTime time.Time `json:"startTime"` EndTime time.Time `json:"endTime"` Method string `json:"method"` Status int `json:"status"` UserAgent string `json:"userAgent"` Referer string `json:"referer"` GoroutinesCount int64 `json:"goroutinesCount"` RequestDurationNanoseconds int64 `json:"requestDurationNanoseconds"` RequestDurationMilliseconds int64 `json:"requestDurationMilliseconds"` RequestBytesCount int64 `json:"requestBytesCount"` ResponseBytesCount int64 `json:"responseBytesCount"` }
RequestMetrics ...
func (*RequestMetrics) Clone ¶ added in v0.7.0
func (r *RequestMetrics) Clone() *RequestMetrics
Clone returns a new RequestMetrics with the same value.
Source Files ¶
- accept.go
- cachecontrol.go
- clickjacking.go
- contentsniffing.go
- contenttype.go
- context.go
- debug.go
- etag.go
- expires.go
- header.go
- hsts.go
- method.go
- metrics.go
- metrics_recorder.go
- metrics_recorder_option.go
- metrics_request.go
- ratelimit.go
- realip.go
- recover.go
- stampede.go
- switch.go
- timeout.go
- umbrella.go
- use.go
- useragent.go
- xssfiltering.go