Documentation
¶
Index ¶
- Constants
- Variables
- func Chain(h http.Handler, ff ...func(http.Handler) http.Handler) http.Handler
- func ChainFunc(hf http.HandlerFunc, ff ...func(http.HandlerFunc) http.HandlerFunc) http.HandlerFunc
- func Decode[V any](w http.ResponseWriter, r *http.Request, sz int, d time.Duration) (V, error)
- func MethodOverride(h http.Handler) http.Handler
- func ParsePattern(s string) (method, host, path string, err error)
- func WithTransport(c *http.Client, url string) *http.Client
- type DecodeError
- type ResponseWriter
- type Transport
Constants ¶
View Source
const ( DefaultReadTimeout = 100 * time.Second // Cloudflare's default read request timeout of 100s DefaultWriteTimeout = 30 * time.Second // Cloudflare's default write request timeout of 30s DefaultIdleTimeout = 900 * time.Second // Cloudflare's default write request timeout of 900s DefaultMaxHeaderBytes = 32 * (1 << 10) DefaultMaxBytes = 1 << 20 // Cloudflare's free tier limits of 100mb )
Variables ¶
View Source
var ErrDecodeBody = errors.New("invalid decode")
View Source
var (
ErrHijackUnsupported = errors.New("the ResponseWriter doesn't support the Hijacker interface")
)
Functions ¶
func ChainFunc ¶
func ChainFunc(hf http.HandlerFunc, ff ...func(http.HandlerFunc) http.HandlerFunc) http.HandlerFunc
ChainFunc applies middlewares to a http.HandlerFunc
func Decode ¶
Decode reads the next JSON-encoded value from a http.Request and returns the value is valid.
If sz or d is set, the max bytes and read deadline of the http.Request can be modified, respectively.
func MethodOverride ¶
MethodOverride is a higher order [http.handlerFunc] which allows the client to override a POST request with a PUT, PATCH or DELETE.
A search query ("_method") can be used or header ("X-HTTP-Method-Override").
func ParsePattern ¶
ParsePattern parses a requst string into method, host (optional) & the path.
func WithTransport ¶
WithTransport wraps the http.Client with a http.Transport that attempts to resolve a relative url if provided.
Types ¶
type DecodeError ¶
func (DecodeError) Error ¶
func (e DecodeError) Error() string
func (DecodeError) Is ¶
func (e DecodeError) Is(target error) bool
type ResponseWriter ¶
type ResponseWriter interface {
http.ResponseWriter
http.Flusher
// Status returns the status code of the response or 0 if the response has not been written.
Status() int
// Written returns whether or not the ResponseWriter has been written.
Written() bool
// Size returns the size of the response body.
Size() int
Unwrap() http.ResponseWriter
// Tee allows the caller to write to multiple writers.
Tee(w io.Writer)
}
func Wrap ¶
func Wrap(w http.ResponseWriter, r *http.Request) ResponseWriter
Wrap http.ResponseWriter into a ResponseWriter.
Source Files
¶
Click to show internal directories.
Click to hide internal directories.