public final class CorsPolicy extends Object
| Modifier and Type | Method and Description |
|---|---|
Set<io.netty.util.AsciiString> |
allowedRequestHeaders()
Returns the allowed set of request headers.
|
Set<HttpMethod> |
allowedRequestMethods()
Returns the allowed set of request methods.
|
static CorsPolicyBuilder |
builder()
Returns a new
CorsPolicyBuilder. |
static CorsPolicyBuilder |
builder(Iterable<String> origins)
Returns a new
CorsPolicyBuilder with the specified origins. |
static CorsPolicyBuilder |
builder(String... origins)
Returns a new
CorsPolicyBuilder with the specified origins. |
Set<io.netty.util.AsciiString> |
exposedHeaders()
Returns a set of headers to be exposed to calling clients.
|
HttpHeaders |
generatePreflightResponseHeaders()
Generates immutable HTTP response headers that should be added to a CORS preflight response.
|
boolean |
isCredentialsAllowed()
Determines if cookies are supported for CORS requests.
|
boolean |
isNullOriginAllowed()
Determines if the policy allows a
"null" origin. |
long |
maxAge()
Gets the
maxAge setting. |
String |
origin()
Returns the allowed origin.
|
Set<String> |
origins()
Returns the set of allowed origins.
|
List<Route> |
routes()
Returns the list of
Routes that this policy is supposed to be applied to. |
String |
toString() |
public static CorsPolicyBuilder builder()
CorsPolicyBuilder.public static CorsPolicyBuilder builder(String... origins)
CorsPolicyBuilder with the specified origins.public static CorsPolicyBuilder builder(Iterable<String> origins)
CorsPolicyBuilder with the specified origins.public String origin()
"Access-Control-Allow-Origin"public List<Route> routes()
Routes that this policy is supposed to be applied to.public boolean isCredentialsAllowed()
By default cookies are not included in CORS requests but if isCredentialsAllowed returns
true cookies will be added to CORS requests. Setting this value to true will set the
CORS "Access-Control-Allow-Credentials" response header to true.
Please note that cookie support needs to be enabled on the client side as well. The client needs to opt-in to send cookies by calling:
xhr.withCredentials = true;
The default value for 'withCredentials' is false in which case no cookies are sent.
Setting this to true will include cookies in cross origin requests.
true if cookies are supported.public long maxAge()
maxAge setting.
When making a preflight request the client has to perform two requests which can be inefficient.
This setting will set the CORS "Access-Control-Max-Age" response header and enable the
caching of the preflight response for the specified time. During this time no preflight
request will be made.
public Set<io.netty.util.AsciiString> exposedHeaders()
During a simple CORS request only certain response headers are made available by the browser, for example using:
xhr.getResponseHeader("Content-Type");
The headers that are available by default are:
Cache-ControlContent-LanguageContent-TypeExpiresLast-ModifiedPragmaTo expose other headers they need to be specified, which is what this method enables by
adding the headers names to the CORS "Access-Control-Expose-Headers" response header.
public Set<HttpMethod> allowedRequestMethods()
"Access-Control-Request-Method" response header.HttpMethods that represent the allowed request methods.public Set<io.netty.util.AsciiString> allowedRequestHeaders()
The header names returned from this method will be used to set the CORS
"Access-Control-Allow-Headers" response header.
public boolean isNullOriginAllowed()
"null" origin.public HttpHeaders generatePreflightResponseHeaders()
HttpHeaders the HTTP response headers to be added.Copyright © 2020 LeanCloud. All rights reserved.