http

package
v0.28.0 Latest Latest
Warning

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

Go to latest
Published: Oct 26, 2026 License: Apache-2.0 Imports: 8 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DecodeJSONBody added in v0.2.41

func DecodeJSONBody(w http.ResponseWriter, r *http.Request, maxBytes int64, dst any) error

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 DiscoverPattern

func DiscoverPattern(patterns []string, r *http.Request) (string, error)

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 GetParam

func GetParam(name string, defaultValue string, r *http.Request) string

func GetParamArray

func GetParamArray(name string, defaultValue []string, r *http.Request) []string

func IsSecure added in v0.2.41

func IsSecure(r *http.Request) bool

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

func SafeReturnPath(p string) string

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

func SameOrigin(raw, scheme string, domains []string) bool

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.

func ValidatePattern

func ValidatePattern(pattern string, r *http.Request) (err error)

Types

type Method

type Method string

func MethodFromString

func MethodFromString(method string) Method

func Methods

func Methods() []Method

Jump to

Keyboard shortcuts

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