livery_cors (livery v0.2.0)
View SourceCORS middleware.
Adds Cross-Origin Resource Sharing headers and answers preflight
OPTIONS requests. Configure it as a stack entry
{livery_cors, Config} where every Config key is optional:
origins—'*'(default), a list of allowed origin binaries, or a predicatefun((binary()) -> boolean()).methods— allowed methods for preflightAccess-Control-Allow-Methods(default the common verb set).headers—mirror(default, echo the request'sAccess-Control-Request-Headers) or an explicit list of header names.expose— header names forAccess-Control-Expose-Headers(default[]).credentials—trueto sendAccess-Control-Allow-Credentials(defaultfalse). With credentials the wildcard origin is never sent; the requestOriginis echoed instead.max_age— seconds forAccess-Control-Max-Ageon preflights.
Vary is set so shared caches stay correct: Origin is added on every
branch whenever the emitted headers depend on the request origin (a
list, a predicate, or credentialed wildcard), and
Access-Control-Request-Headers is added on mirroring preflights. A
plain non-credentialed '*' configuration is origin-independent and
adds no Vary.
Summary
Functions
Apply CORS headers, answering preflight requests directly.
Functions
-spec call(livery_req:req(), livery_middleware:next(), map() | undefined) -> livery_resp:resp().
Apply CORS headers, answering preflight requests directly.