Documentation
¶
Overview ¶
Package httpx holds the small HTTP helpers vlatte's packages share: the mock servers, the webhook package, the recipes and the vlatte command.
Index ¶
- Constants
- func IsBaseURL(s string) bool
- func IsToken(s string) bool
- func ListenAddr(addr string) bool
- func NewDialer(allow, deny []netip.Prefix) *net.Dialer
- func NewWebhookTransport(allow, deny []netip.Prefix) *http.Transport
- func ParsePrefixes(list []string) ([]netip.Prefix, error)
- func URLPath(s string) (path, escaped string, ok bool)
- func Wait(ctx context.Context, d time.Duration) error
- type AcceptRange
- type Preference
Constants ¶
const DefaultWebhookTimeout = 10 * time.Second
DefaultWebhookTimeout is how long a webhook waits for its answer when nothing sets its timeout.
Variables ¶
This section is empty.
Functions ¶
func IsBaseURL ¶ added in v1.3.0
IsBaseURL reports whether s is a URL that others are made from by appending a path: absolute, with a host, and with no query or fragment, not even an empty one.
func ListenAddr ¶
ListenAddr reports whether addr is an address a server can listen on: empty, a port, or host:port.
func NewDialer ¶
NewDialer returns a dialer of the connections a server opens, with the limits of http.DefaultTransport's, which refuses an address in deny, or outside allow when allow isn't empty, and the unspecified address with either set, with vlatte.ErrOutboundRefused. It checks the address it connects to, once resolved.
func NewWebhookTransport ¶
NewWebhookTransport returns the transport a server gives webhooks when its config has none. It is the server's: Close closes its idle connections. It has the limits of http.DefaultTransport, built here rather than copied, as a program may have replaced http.DefaultTransport, and dials as NewDialer does with allow and deny.
func ParsePrefixes ¶
ParsePrefixes parses the address ranges of an outbound setting, each in CIDR form, for NewDialer.
Types ¶
type AcceptRange ¶
AcceptRange is a media range of an Accept header, such as application/json, text/* or */*, and its weight.
func ParseAccept ¶
func ParseAccept(header []string) []AcceptRange
ParseAccept parses the media ranges of Accept headers, in the order they come, leaving out those it can't parse and those whose weight isn't one RFC 9110 allows, from 0 to 1.
func (AcceptRange) Match ¶
func (r AcceptRange) Match(mediaType string) int
Match tells how specifically r matches mediaType: 3 by name, 2 by type, as text/*, 1 as */*, 0 not.
type Preference ¶
Preference is how much the ranges of Accept headers want a media type: Q is the weight of the range that matches it, Specificity tells how specifically that range matches, as AcceptRange.Match does, and Index is where the range sits among the ranges. A media type no range matches has a zero Preference.
func Prefer ¶
func Prefer(ranges []AcceptRange, names ...string) Preference
Prefer returns how much ranges want a media type with one of names: the most specific range that matches a name decides, as RFC 9110 reads Accept, the heaviest of those when several are as specific, and the first of those when they weigh the same.