Documentation
¶
Overview ¶
Package shared holds helpers used by more than one Zinc middleware package.
Index ¶
- func Config[T any](name string, configs []T) T
- func EscapedTail(u *url.URL, n int) string
- func ExpandTarget(to, tail string) string
- func ExternalTarget(to string) bool
- func PathWithRawQuery(path, rawQuery string) string
- func ResponseStatus(rw zinc.ResponseWriter, err error) int
- func SameSitePath(path string) string
- type RoutingWarning
- type Rules
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Config ¶
Config returns the configuration passed to a middleware's New, or the zero value when there is none, so every field falls back to its default.
func EscapedTail ¶ added in v0.7.2
EscapedTail returns the escaped form of the last n bytes of u.Path, so a redirect built from it keeps encoded characters such as %2F encoded.
func ExpandTarget ¶ added in v0.7.2
ExpandTarget replaces the first "*" in to with tail, or appends tail when to has none.
func ExternalTarget ¶ added in v0.7.2
ExternalTarget reports whether a rule's target names a scheme or host, so it is meant to leave the site. Decide this on the configured target, before any part of the request path is put into it.
func PathWithRawQuery ¶
PathWithRawQuery appends rawQuery to path.
func ResponseStatus ¶
func ResponseStatus(rw zinc.ResponseWriter, err error) int
ResponseStatus is the status a request ended with: the one written, or the one the error handler sends for err.
func SameSitePath ¶ added in v0.7.2
SameSitePath makes an escaped request path safe to send as a redirect target: the result starts with exactly one slash, so a browser resolves it on this site, and backslashes, spaces and control characters are escaped. A path starting "//" or "/\" would otherwise name another host.
Types ¶
type RoutingWarning ¶ added in v0.5.2
type RoutingWarning struct {
// contains filtered or unexported fields
}
RoutingWarning warns once when middleware that changes which route a request takes, such as redirect or rewrite, runs after a route was already chosen. On a group Zinc refuses it at registration, so this catches the remaining case, a single route: it works for that path only, and a rewrite can no longer change the route.
func NewRoutingWarning ¶ added in v0.5.2
func NewRoutingWarning(name string) *RoutingWarning
NewRoutingWarning returns a RoutingWarning for the middleware called name.
func (*RoutingWarning) Check ¶ added in v0.5.2
func (w *RoutingWarning) Check(c *zinc.Context)
Check logs the warning the first time c has a matched route.
type Rules ¶ added in v0.7.3
type Rules struct {
// contains filtered or unexported fields
}
Rules is a compiled set of path rules, as used by rewrite, redirect and proxy. A pattern ending in "*" matches any path starting with the text before the "*"; any other pattern matches one path exactly.
When several rules match a path, the winner is fixed when the rules are compiled, not by map order: an exact rule beats every "*" rule, and among "*" rules the one with the longest literal prefix wins. Two different prefixes that both match a path can't have the same length, so there are no ties to break.
func CompileRules ¶ added in v0.7.3
CompileRules copies rules into precedence order, dropping empty patterns.