httpmw

package
v0.1.12 Latest Latest
Warning

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

Go to latest
Published: Sep 21, 2023 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrLimitReached = xerrors.Errorf("i/o limit reached")

Functions

func LimitBody

func LimitBody(n int64) func(h http.Handler) http.Handler

func RateLimit

func RateLimit(cfg RateLimitConfig) func(http.Handler) http.Handler

RateLimit returns a handler that limits requests based on IP.

func SetBodyLimit

func SetBodyLimit(r *http.Request, n int64)

Types

type LimitReader

type LimitReader struct {
	Limit int64
	N     int64
	R     io.Reader
}

LimitReader is like io.LimitReader except that it returns ErrLimitReached when the limit has been reached.

func (*LimitReader) Read

func (l *LimitReader) Read(p []byte) (int, error)

func (*LimitReader) Reset

func (l *LimitReader) Reset(n int64)

type LimitedBody

type LimitedBody struct {
	R *LimitReader
	// contains filtered or unexported fields
}

func (LimitedBody) Close

func (r LimitedBody) Close() error

func (LimitedBody) Read

func (r LimitedBody) Read(p []byte) (n int, err error)

type RateLimitConfig added in v0.1.6

type RateLimitConfig struct {
	Log slog.Logger

	// Count of the amount of requests allowed in the Window. If the Count is
	// zero, the rate limiter is disabled.
	Count  int
	Window time.Duration

	// RealIPHeader is the header to use to get the real IP address of the
	// request. If this is empty, the request's RemoteAddr is used.
	RealIPHeader string
}

Jump to

Keyboard shortcuts

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