httpidletimeout

package
v0.139.0 Latest Latest
Warning

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

Go to latest
Published: Apr 12, 2023 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

Package httpidletimeout implements an HTTP middleware that triggers after a given timeout.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Middleware

type Middleware struct {
	// contains filtered or unexported fields
}

Middleware implements an HTTP middleware that triggers after an idle timeout (as in time since the last request completed). To initialize a Middleware, use New() passing the idle timeout, start it via Start() and finally use Wait() to wait for the idle timeout to trigger. To exit cleanly, Cancel() should be called at some point after Start() to free the resources associated with the Middlware (e.g. with a defer after New()).

func New

func New(timeout time.Duration, opts ...Option) *Middleware

New returns a new Middleware which will timeout after the given duration. See Middleware for more information.

func (*Middleware) Cancel

func (m *Middleware) Cancel()

Cancel makes the Middleware stop triggering timeouts after its timeout interval. An stopped Middleware can't be restarted again.

func (*Middleware) Handler

func (m *Middleware) Handler(next http.Handler) http.Handler

Handler returns a handler wrapped by the Middleware

func (*Middleware) HandlerFunc

func (m *Middleware) HandlerFunc(next http.HandlerFunc) http.Handler

HandlerFunc is a shorthand for wrapping http.HandlerFunc handlers

func (*Middleware) Start

func (m *Middleware) Start()

Start makes the Middleware start counting towards the idle timeout. After Start(), Cancel() should be called at some point.

func (*Middleware) Wait

func (m *Middleware) Wait(ctx context.Context) error

Wait blocks until the timeout triggers or until the given Context is cancelled. If the timeout triggered, the return value will be nil. Otherwise, it returns ctx.Err().

type Option added in v0.115.0

type Option func(o *options)

func WithSkip added in v0.115.0

func WithSkip(fn SkipFunc) Option

WithSkip configures a skip function for the timer See SkipFunc.

type SkipFunc added in v0.115.0

type SkipFunc func(r *http.Request) bool

SkipFunc allows filtering requests to make them skip resetting the idle timer. See WithSkip()

Jump to

Keyboard shortcuts

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