xhttp

package
v0.12.0 Latest Latest
Warning

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

Go to latest
Published: Nov 1, 2025 License: BSD-3-Clause Imports: 18 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 ErrDecodeBody = errors.New("invalid decode")
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 Decode

func Decode[V any](w http.ResponseWriter, r *http.Request, sz int, d time.Duration) (V, error)

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

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

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

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

func PingHandler added in v0.12.0

func PingHandler(p Pinger, ttl time.Duration) http.Handler

PingHandler adds simple ping deduplication by allowing the Pinger to run at most once at a time and briefly caching its result.

func WithTransport

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 DecodeError

type DecodeError struct {
	Code   int
	Reason string
}

func (DecodeError) Error

func (e DecodeError) Error() string

func (DecodeError) Is

func (e DecodeError) Is(target error) bool

type Pinger added in v0.12.0

type Pinger interface {
	Ping(context.Context) error
}

Pinger abstracts a ping operation that reports reachability via error.

type PingerFunc added in v0.12.0

type PingerFunc func(context.Context) error

PingerFunc

func (PingerFunc) Ping added in v0.12.0

func (f PingerFunc) Ping(ctx context.Context) error

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

type Transport struct {
	http.RoundTripper
	URL string
}

Transport attempts to resolve a relative url if provided.

func (*Transport) RoundTrip

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

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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