stream

package
v1.4.2 Latest Latest
Warning

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

Go to latest
Published: Nov 4, 2022 License: Apache-2.0 Imports: 5 Imported by: 4 modules, 4 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package stream provides http.Handler middleware that passes-through the entire request

Stream works around several limitations caused by buffering implementations, but also introduces certain risks.

Workarounds for buffering limitations: 1. Streaming really large chunks of data (large file transfers, or streaming videos, etc.)

2. Streaming (chunking) sparse data. For example, an implementation might send a health check or a heart beat over a long-lived connection. This does not play well with buffering.

Risks: 1. Connections could survive for very long periods of time.

2. There is no easy way to enforce limits on size/time of a connection.

Examples of a streaming middleware:

// sample HTTP handler
handler := http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
  w.Write([]byte("hello"))
})

// Stream will literally pass through to the next handler without ANY buffering
// or validation of the data.
stream.New(handler)

Index

Constants

View Source
const (
	// DefaultMaxBodyBytes No limit by default.
	DefaultMaxBodyBytes = -1
)

Variables

This section is empty.

Functions

func IsValidExpression

func IsValidExpression(expr string) bool

IsValidExpression check if it's a valid expression.

func Logger

func Logger(l *log.Logger) optSetter

Logger defines the logger the streamer will use.

It defaults to logrus.StandardLogger(), the global logger used by logrus.

Types

type Stream

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

Stream is responsible for buffering requests and responses It buffers large requests and responses to disk,.

func New

func New(next http.Handler, setters ...optSetter) (*Stream, error)

New returns a new streamer middleware. New() function supports optional functional arguments.

func (*Stream) ServeHTTP

func (s *Stream) ServeHTTP(w http.ResponseWriter, req *http.Request)

func (*Stream) Wrap

func (s *Stream) Wrap(next http.Handler) error

Wrap sets the next handler to be called by stream handler.

Jump to

Keyboard shortcuts

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