httputil

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Apr 11, 2025 License: BSD-3-Clause Imports: 12 Imported by: 0

Documentation

Index

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 (
	ErrHijackUnsupported = errors.New("the ResponseWriter doesn't support the Hijacker interface")
)

Functions

func Chain

func Chain(h http.Handler, ff ...func(http.Handler) http.Handler) http.Handler

Chain applies middlewares to a http.Handler

func ChainFunc

func ChainFunc(hf http.HandlerFunc, ff ...func(http.HandlerFunc) http.HandlerFunc) http.HandlerFunc

ChainFunc applies middlewares to a http.HandlerFunc

func MethodOverride

func MethodOverride(h http.Handler) http.Handler

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 added in v0.4.0

func ParsePattern(s string) (method, host, path string, err error)

ParsePattern parses a requst string into method, host (optional) & the path.

func WithTransport added in v0.4.0

func WithTransport(c *http.Client, url string) *http.Client

WithTransport wraps the http.Client with a http.Transport that attempts to resolve a relative url if provided.

Types

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

Wrap http.ResponseWriter into a ResponseWriter.

type Transport added in v0.4.0

type Transport struct {
	http.RoundTripper
	URL string
}

Transport attempts to resolve a relative url if provided.

func (*Transport) RoundTrip added in v0.4.0

func (t *Transport) RoundTrip(r *http.Request) (*http.Response, error)

Jump to

Keyboard shortcuts

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