Documentation
¶
Overview ¶
Package cors is the Fetch standard's CORS protocol as browsers apply it: when a cross-origin fetch() or XHR needs a preflight, whether a preflight's answer or a redirect allows the request, and the preflight cache. Sending a preflight is the root package's.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Check ¶
Check returns why a response's headers fail the Fetch standard's CORS check for a request from origin, with credentials or not, or "".
func CheckPreflight ¶
CheckPreflight returns why a preflight's response does not allow the request (the Fetch standard's CORS-preflight fetch), or "".
func PreflightHeaders ¶
PreflightHeaders returns the Config.Header (config) a CORS preflight gets: those its kind's header lists name, such as a User-Agent or Accept-Language override, so it goes as the request does; never the page's own, such as an API key, which a preflight never carries.
func SafelistedMethod ¶
SafelistedMethod reports a CORS-safelisted method: one a request may use without a preflight.
Types ¶
type Cache ¶
type Cache struct {
// contains filtered or unexported fields
}
Cache remembers successful preflights: per key, until when each method ("m:PUT") and header name ("h:x-a") is allowed. The zero Cache is empty and ready to use.
type Need ¶
type Need struct {
Method string
// Headers are the request's CORS-unsafe header names, lowercase,
// sorted, once each: Access-Control-Request-Headers.
Headers []string
// contains filtered or unexported fields
}
Need is what a request's preflight asks for it.
func Preflight ¶
func Preflight(req *http.Request, origin string, credentialed bool, h http.Header, force bool) *Need
Preflight returns the preflight a browser sends before a CORS request from origin (the root's preflightOrigin; "" for none, which is nil) with a non-safelisted method or header, or nil. With force it ignores method and headers (a hop inheriting its chain's preflight).