Documentation
¶
Index ¶
- func DecodeJSONBody(w http.ResponseWriter, r *http.Request, maxBytes int64, dst any) error
- func DiscoverPattern(patterns []string, r *http.Request) (string, error)
- func GetAcceptLanguage(r *http.Request, defaultLanguage string, languages []language.Tag) (language.Tag, error)
- func GetLang(r *http.Request, defaultLanguage string, languages []language.Tag) (language.Tag, error)
- func GetParam(name string, defaultValue string, r *http.Request) string
- func GetParamArray(name string, defaultValue []string, r *http.Request) []string
- func IsSecure(r *http.Request) bool
- func SafeReturnPath(p string) string
- func SameOrigin(raw, scheme string, domains []string) bool
- func ValidatePattern(pattern string, r *http.Request) (err error)
- type Method
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DecodeJSONBody ¶ added in v0.2.41
DecodeJSONBody reads a JSON document from r.Body into dst, refusing bodies larger than maxBytes and rejecting unknown fields. Use this everywhere instead of a bare json.NewDecoder(r.Body).Decode to avoid memory-exhaustion DoS from untrusted clients.
func GetAcceptLanguage ¶ added in v0.24.0
func GetAcceptLanguage(r *http.Request, defaultLanguage string, languages []language.Tag) (language.Tag, error)
GetAcceptLanguage negotiates the response language from the Accept-Language header alone, falling back to defaultLanguage. Use it where the URL is not the user's own choice (the consent page: whoever built the authorize request chose its query).
func GetLang ¶
func GetLang(r *http.Request, defaultLanguage string, languages []language.Tag) (language.Tag, error)
GetLang negotiates the response language: the l10n path or query parameter when present, else the Accept-Language header (see GetAcceptLanguage).
func GetParamArray ¶
func IsSecure ¶ added in v0.2.41
IsSecure reports whether the request reached us over HTTPS. It returns true when the request hit Go's TLS terminator directly, or when a trusted proxy signals it via X-Forwarded-Proto. Use this — not r.URL.Scheme — when deciding whether to set the Secure attribute on outgoing cookies, because r.URL.Scheme is empty for server-received requests.
func SafeReturnPath ¶ added in v0.2.41
SafeReturnPath returns p if it is safe to use as a same-origin redirect target, otherwise "/". Anything that a browser would resolve to a different origin (absolute URLs, scheme-relative "//evil.com" forms, backslash variants used to evade naive prefix checks, non-http schemes) collapses to "/". This is the guard for ?return=… / state= values that get fed into http.Redirect.
func SameOrigin ¶ added in v0.23.0
SameOrigin reports whether raw (an Origin value or a Referer URL) has the given scheme and names one of domains. A domain that carries a port must match it exactly; a domain without one matches the scheme's default port or no port. "null" and anything unparseable never match.
Types ¶
type Method ¶
type Method string
const ( Connect Method = http.MethodConnect Delete Method = http.MethodDelete Get Method = http.MethodGet Head Method = http.MethodHead Options Method = http.MethodOptions Patch Method = http.MethodPatch Post Method = http.MethodPost Put Method = http.MethodPut Trace Method = http.MethodTrace )