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 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 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 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.
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 )