httputil

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Sep 18, 2021 License: MIT Imports: 2 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Middleware

type Middleware = func(next http.Handler) http.Handler

func ApplyIf

func ApplyIf(cond func(r *http.Request) bool, mw Middleware) Middleware

ApplyIf returns new Middlware that wraps `next` handler if `cond` returns true otherwise just delegates to `next` handler.

You can determine `cond` result according to incoming *http.Request's value.

func Stack added in v0.2.0

func Stack(middlewares ...Middleware) Middleware

Stack returns new Middleware that runs `middlewares` sequentially.

It is useful for applying multiple middlewares and reusing them.

type TeeResponseWriter added in v0.3.0

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

TeeResponseWriter is an http.ResponseWriter implementation and writes response body into original http.ResponseWriter and given io.Writer.

You can use TeeResponseWriter for capturing sent response body in http.Handler.

func NewTeeResponseWriter added in v0.3.0

func NewTeeResponseWriter(rw http.ResponseWriter, buf io.Writer) *TeeResponseWriter

func (*TeeResponseWriter) Header added in v0.3.0

func (w *TeeResponseWriter) Header() http.Header

func (*TeeResponseWriter) StatusCode added in v0.3.0

func (w *TeeResponseWriter) StatusCode() int

StatusCode returns captured response status.

The return value may be zero if no response sent.

func (*TeeResponseWriter) Write added in v0.3.0

func (w *TeeResponseWriter) Write(b []byte) (int, error)

func (*TeeResponseWriter) WriteHeader added in v0.3.0

func (w *TeeResponseWriter) WriteHeader(statusCode int)

Jump to

Keyboard shortcuts

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