public final class ChainedCorsPolicyBuilder extends Object
CorsPolicy.
This class can only be created through the CorsServiceBuilder.andForOrigins(String...) or
CorsServiceBuilder.andForOrigin(String) method of the CorsServiceBuilder.
Calling and() method will return the control to CorsServiceBuilder.
| Modifier and Type | Method and Description |
|---|---|
ChainedCorsPolicyBuilder |
allowCredentials()
Enables cookies to be added to CORS requests.
|
ChainedCorsPolicyBuilder |
allowNullOrigin()
Enables a successful CORS response with a
"null" value for the CORS response header
"Access-Control-Allow-Origin". |
ChainedCorsPolicyBuilder |
allowRequestHeaders(CharSequence... headers)
Specifies the headers that should be returned in the CORS
"Access-Control-Allow-Headers"
response header. |
ChainedCorsPolicyBuilder |
allowRequestHeaders(Iterable<? extends CharSequence> headers)
Specifies the headers that should be returned in the CORS
"Access-Control-Allow-Headers"
response header. |
ChainedCorsPolicyBuilder |
allowRequestMethods(HttpMethod... methods)
Specifies the allowed set of HTTP request methods that should be returned in the
CORS
"Access-Control-Allow-Methods" response header. |
ChainedCorsPolicyBuilder |
allowRequestMethods(Iterable<HttpMethod> methods)
Specifies the allowed set of HTTP request methods that should be returned in the
CORS
"Access-Control-Allow-Methods" response header. |
CorsServiceBuilder |
and()
Returns the parent
CorsServiceBuilder. |
ChainedCorsPolicyBuilder |
andForOrigin(String origin)
Creates a new instance of
ChainedCorsPolicyBuilder
added to the parent CorsServiceBuilder. |
ChainedCorsPolicyBuilder |
andForOrigins(String... origins)
Creates a new instance of
ChainedCorsPolicyBuilder
added to the parent CorsServiceBuilder. |
ChainedCorsPolicyBuilder |
disablePreflightResponseHeaders()
Specifies that no preflight response headers should be added to a preflight response.
|
ChainedCorsPolicyBuilder |
exposeHeaders(CharSequence... headers)
Specifies the headers to be exposed to calling clients.
|
ChainedCorsPolicyBuilder |
exposeHeaders(Iterable<? extends CharSequence> headers)
Specifies the headers to be exposed to calling clients.
|
ChainedCorsPolicyBuilder |
maxAge(long maxAge)
Sets the CORS
"Access-Control-Max-Age" response header and enables the
caching of the preflight response for the specified time. |
ChainedCorsPolicyBuilder |
preflightResponseHeader(CharSequence name,
Iterable<?> values)
Specifies HTTP response headers that should be added to a CORS preflight response.
|
ChainedCorsPolicyBuilder |
preflightResponseHeader(CharSequence name,
Object... values)
Specifies HTTP response headers that should be added to a CORS preflight response.
|
ChainedCorsPolicyBuilder |
preflightResponseHeader(CharSequence name,
Supplier<?> valueSupplier)
Specifies HTTP response headers that should be added to a CORS preflight response.
|
ChainedCorsPolicyBuilder |
route(String pathPattern)
Adds a path pattern that this policy is supposed to be applied to.
|
String |
toString() |
public CorsServiceBuilder and()
CorsServiceBuilder.public ChainedCorsPolicyBuilder andForOrigins(String... origins)
ChainedCorsPolicyBuilder
added to the parent CorsServiceBuilder.public ChainedCorsPolicyBuilder andForOrigin(String origin)
ChainedCorsPolicyBuilder
added to the parent CorsServiceBuilder.public ChainedCorsPolicyBuilder route(String pathPattern)
pathPattern - the path pattern that this policy is supposed to be applied tothis to support method chaining.public ChainedCorsPolicyBuilder allowNullOrigin()
"null" value for the CORS response header
"Access-Control-Allow-Origin". Web browsers may set the "Origin" request header to
"null" if a resource is loaded from the local file system.this to support method chaining.public ChainedCorsPolicyBuilder allowCredentials()
"Access-Control-Allow-Credentials" response header
to true. By default, cookies are not included in CORS requests.
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.
this to support method chaining.public ChainedCorsPolicyBuilder maxAge(long maxAge)
"Access-Control-Max-Age" response header and enables the
caching of the preflight response for the specified time. During this time no preflight
request will be made.maxAge - the maximum time, in seconds, that the preflight response may be cached.this to support method chaining.public ChainedCorsPolicyBuilder exposeHeaders(CharSequence... headers)
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 to the CORS "Access-Control-Expose-Headers" response header.
headers - the values to be added to the "Access-Control-Expose-Headers" response headerthis to support method chaining.public ChainedCorsPolicyBuilder exposeHeaders(Iterable<? extends CharSequence> headers)
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 to the CORS "Access-Control-Expose-Headers" response header.
headers - the values to be added to the "Access-Control-Expose-Headers" response headerthis to support method chaining.public ChainedCorsPolicyBuilder allowRequestMethods(HttpMethod... methods)
"Access-Control-Allow-Methods" response header.methods - the HttpMethods that should be allowed.this to support method chaining.public ChainedCorsPolicyBuilder allowRequestMethods(Iterable<HttpMethod> methods)
"Access-Control-Allow-Methods" response header.methods - the HttpMethods that should be allowed.this to support method chaining.public ChainedCorsPolicyBuilder allowRequestHeaders(CharSequence... headers)
"Access-Control-Allow-Headers"
response header.
If a client specifies headers on the request, for example by calling:
xhr.setRequestHeader('My-Custom-Header', 'SomeValue');
The server will receive the above header name in the "Access-Control-Request-Headers" of the
preflight request. The server will then decide if it allows this header to be sent for the
real request (remember that a preflight is not the real request but a request asking the server
if it allows a request).headers - the headers to be added to
the preflight "Access-Control-Allow-Headers" response header.this to support method chaining.public ChainedCorsPolicyBuilder allowRequestHeaders(Iterable<? extends CharSequence> headers)
"Access-Control-Allow-Headers"
response header.
If a client specifies headers on the request, for example by calling:
xhr.setRequestHeader('My-Custom-Header', 'SomeValue');
The server will receive the above header name in the "Access-Control-Request-Headers" of the
preflight request. The server will then decide if it allows this header to be sent for the
real request (remember that a preflight is not the real request but a request asking the server
if it allows a request).headers - the headers to be added to
the preflight "Access-Control-Allow-Headers" response header.this to support method chaining.public ChainedCorsPolicyBuilder preflightResponseHeader(CharSequence name, Object... values)
An intermediary like a load balancer might require that a CORS preflight request have certain headers set. This enables such headers to be added.
name - the name of the HTTP header.values - the values for the HTTP header.this to support method chaining.public ChainedCorsPolicyBuilder preflightResponseHeader(CharSequence name, Iterable<?> values)
An intermediary like a load balancer might require that a CORS preflight request have certain headers set. This enables such headers to be added.
name - the name of the HTTP header.values - the values for the HTTP header.this to support method chaining.public ChainedCorsPolicyBuilder preflightResponseHeader(CharSequence name, Supplier<?> valueSupplier)
An intermediary like a load balancer might require that a CORS preflight request have certain headers set. This enables such headers to be added.
Some values must be dynamically created when the HTTP response is created, for
example the "Date" response header. This can be accomplished by using a Supplier
which will have its Supplier.get() method invoked when the HTTP response is created.
name - the name of the HTTP header.valueSupplier - a Supplier which will be invoked at HTTP response creation.this to support method chaining.public ChainedCorsPolicyBuilder disablePreflightResponseHeaders()
this to support method chaining.Copyright © 2020 LeanCloud. All rights reserved.