dada

package
v0.0.0-...-5f47e43 Latest Latest
Warning

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

Go to latest
Published: Feb 4, 2020 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ReqTooLargeError = fmt.Errorf("request is too large")

Functions

func LimitReaderWithErr

func LimitReaderWithErr(r io.ReadCloser, n int64, err error) io.ReadCloser

LimitReader returns a Reader that reads from r but stops with an error after n bytes. The underlying implementation is a *LimitedReaderWithErr.

func ServerWithDefenseAgainstDarkArts

func ServerWithDefenseAgainstDarkArts(maxRequestSize int, timeout time.Duration,
	muxer *mux.Router) *http.Server

Attach middleware to Echo to prevent slow-loris attacks and DDoS-es by extremely large requests.

Types

type LimitedReaderWithErr

type LimitedReaderWithErr struct {
	Reader    io.ReadCloser // underlying reader
	BytesLeft int64         // max bytes remaining
	Error     error         // the error to return in case of too much data
}

A LimitedReaderWithErr reads from Reader but limits the amount of data returned to just BytesLeft bytes. Each call to Read updates BytesLeft to reflect the new amount remaining. Read returns error when BytesLeft <= 0 or when the underlying Reader returns EOF.

func (*LimitedReaderWithErr) Close

func (l *LimitedReaderWithErr) Close() error

func (*LimitedReaderWithErr) Read

func (l *LimitedReaderWithErr) Read(p []byte) (n int, err error)

Jump to

Keyboard shortcuts

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