Package com.jsgalactic.axiom.security
Class Cors.Builder
java.lang.Object
com.jsgalactic.axiom.security.Cors.Builder
- Enclosing class:
Cors
Configures
Cors. Not thread-safe; build once at startup.-
Method Summary
Modifier and TypeMethodDescriptionLets browsers send credentials (cookies,Authorization) with cross-origin requests; incompatible withanyOrigin().allowHeaders(String... headers) Sets the request headers a preflight may ask for (none by default).allowMethods(String... methods) Sets the methods a preflight may request, replacing the default ofGETandHEAD.allowOrigin(String origin) Allows one origin.Allows every origin withAccess-Control-Allow-Origin: *, for public APIs that never receive credentials.build()Builds the middleware.exposeHeaders(String... headers) Makes response headers readable by the page's script.Sets how long a browser may cache a preflight answer.
-
Method Details
-
allowOrigin
Allows one origin. Call again for more.- Parameters:
origin- exact serialized origin:httporhttps, a host name or IP literal and an optional port, with no path, wildcard or user information- Returns:
- this builder
- Throws:
IllegalArgumentException- for anything else, including*(useanyOrigin()) andnull
-
anyOrigin
Allows every origin withAccess-Control-Allow-Origin: *, for public APIs that never receive credentials. Cannot be combined withallowCredentials().- Returns:
- this builder
-
allowMethods
Sets the methods a preflight may request, replacing the default ofGETandHEAD. A method is still only granted if the route allows it.- Parameters:
methods- HTTP method tokens, upper case, never*- Returns:
- this builder
- Throws:
IllegalArgumentException- for a wildcard, an invalid token or an empty list
-
allowHeaders
Sets the request headers a preflight may ask for (none by default). Matching is case-insensitive. Headers the Fetch standard always permits need not be listed.- Parameters:
headers- header name tokens, never*- Returns:
- this builder
-
exposeHeaders
Makes response headers readable by the page's script.- Parameters:
headers- header name tokens, never*- Returns:
- this builder
-
allowCredentials
Lets browsers send credentials (cookies,Authorization) with cross-origin requests; incompatible withanyOrigin().- Returns:
- this builder
-
maxAge
Sets how long a browser may cache a preflight answer.- Parameters:
maxAge- zero (no header) to 24 hours, whole seconds; 10 minutes by default- Returns:
- this builder
-
build
Builds the middleware.- Returns:
- the immutable middleware
- Throws:
IllegalStateException- without an origin, or foranyOrigin()combined with origins or credentials
-