package connlimit
import "github.com/gravitational/oxy/connlimit"
package connlimit provides control over simultaneous connections coming from the same source
Index ¶
- type ConnErrHandler
- type ConnLimitOption
- type ConnLimiter
- func New(next http.Handler, extract utils.SourceExtractor, maxConnections int64, options ...ConnLimitOption) (*ConnLimiter, error)
- func (cl *ConnLimiter) Acquire(token string, amount int64) error
- func (cl *ConnLimiter) Release(token string, amount int64)
- func (cl *ConnLimiter) ServeHTTP(w http.ResponseWriter, r *http.Request)
- func (cl *ConnLimiter) Wrap(h http.Handler)
- type MaxConnError
Types ¶
type ConnErrHandler ¶
type ConnErrHandler struct { }
func (*ConnErrHandler) ServeHTTP ¶
func (e *ConnErrHandler) ServeHTTP(w http.ResponseWriter, req *http.Request, err error)
type ConnLimitOption ¶
type ConnLimitOption func(l *ConnLimiter) error
func ErrorHandler ¶
func ErrorHandler(h utils.ErrorHandler) ConnLimitOption
ErrorHandler sets error handler of the server
func Logger ¶
func Logger(l utils.Logger) ConnLimitOption
Logger sets the logger that will be used by this middleware.
type ConnLimiter ¶
type ConnLimiter struct {
// contains filtered or unexported fields
}
ConnLimiter tracks concurrent connection per token and is capable of rejecting connections if they are failed
func New ¶
func New(next http.Handler, extract utils.SourceExtractor, maxConnections int64, options ...ConnLimitOption) (*ConnLimiter, error)
New returns a new connection limiter
func (*ConnLimiter) Acquire ¶
func (cl *ConnLimiter) Acquire(token string, amount int64) error
Acquire tries to acquire connections for a token
func (*ConnLimiter) Release ¶
func (cl *ConnLimiter) Release(token string, amount int64)
Release releases connections for token
func (*ConnLimiter) ServeHTTP ¶
func (cl *ConnLimiter) ServeHTTP(w http.ResponseWriter, r *http.Request)
ServeHTTP reserves a connection, sends requests to handler and releases the connection
func (*ConnLimiter) Wrap ¶
func (cl *ConnLimiter) Wrap(h http.Handler)
Wrap wraps HTTP handler
type MaxConnError ¶
type MaxConnError struct {
// contains filtered or unexported fields
}
func (*MaxConnError) Error ¶
func (m *MaxConnError) Error() string
Source Files ¶
- Version
- v0.0.0-20231219172753-f855322f2a6c (latest)
- Published
- Dec 19, 2023
- Platform
- linux/amd64
- Imports
- 4 packages
- Last checked
- 5 months ago –
Tools for package owners.