public final class CorsConfigBuilder extends Object
CorsConfig
instance.Modifier and Type | Method and Description |
---|---|
CorsConfigBuilder |
allowCredentials()
By default cookies are not included in CORS requests, but this method will enable cookies to
be added to CORS requests.
|
CorsConfigBuilder |
allowedRequestHeaders(CharSequence... headers)
Specifies the if headers that should be returned in the CORS 'Access-Control-Allow-Headers'
response header.
|
CorsConfigBuilder |
allowedRequestHeaders(String... headers)
Specifies the if headers that should be returned in the CORS 'Access-Control-Allow-Headers'
response header.
|
CorsConfigBuilder |
allowedRequestMethods(HttpMethod... methods)
Specifies the allowed set of HTTP Request Methods that should be returned in the
CORS 'Access-Control-Request-Method' response header.
|
CorsConfigBuilder |
allowNullOrigin()
Web browsers may set the 'Origin' request header to 'null' if a resource is loaded
from the local file system.
|
CorsConfigBuilder |
allowPrivateNetwork()
Web browsers may set the 'Access-Control-Request-Private-Network' request header if a resource is loaded
from a local network.
|
CorsConfig |
build()
Builds a
CorsConfig with settings specified by previous method calls. |
CorsConfigBuilder |
disable()
Disables CORS support.
|
CorsConfigBuilder |
exposeHeaders(CharSequence... headers)
Specifies the headers to be exposed to calling clients.
|
CorsConfigBuilder |
exposeHeaders(String... headers)
Specifies the headers to be exposed to calling clients.
|
static CorsConfigBuilder |
forAnyOrigin()
Creates a Builder instance with it's origin set to '*'.
|
static CorsConfigBuilder |
forOrigin(String origin)
Creates a
CorsConfigBuilder instance with the specified origin. |
static CorsConfigBuilder |
forOrigins(String... origins)
Creates a
CorsConfigBuilder instance with the specified origins. |
CorsConfigBuilder |
maxAge(long max)
When making a preflight request the client has to perform two request with can be inefficient.
|
CorsConfigBuilder |
noPreflightResponseHeaders()
Specifies that no preflight response headers should be added to a preflight response.
|
<T> CorsConfigBuilder |
preflightResponseHeader(CharSequence name,
Callable<T> valueGenerator)
Returns HTTP response headers that should be added to a CORS preflight response.
|
<T> CorsConfigBuilder |
preflightResponseHeader(CharSequence name,
Iterable<T> value)
Returns HTTP response headers that should be added to a CORS preflight response.
|
CorsConfigBuilder |
preflightResponseHeader(CharSequence name,
Object... values)
Returns HTTP response headers that should be added to a CORS preflight response.
|
CorsConfigBuilder |
shortCircuit()
Specifies that a CORS request should be rejected if it's invalid before being
further processing.
|
public static CorsConfigBuilder forAnyOrigin()
public static CorsConfigBuilder forOrigin(String origin)
CorsConfigBuilder
instance with the specified origin.CorsConfigBuilder
to support method chaining.public static CorsConfigBuilder forOrigins(String... origins)
CorsConfigBuilder
instance with the specified origins.CorsConfigBuilder
to support method chaining.public CorsConfigBuilder allowNullOrigin()
"null"
value for the CORS response header 'Access-Control-Allow-Origin'.CorsConfigBuilder
to support method chaining.public CorsConfigBuilder disable()
CorsConfigBuilder
to support method chaining.public CorsConfigBuilder exposeHeaders(String... headers)
xhr.getResponseHeader("Content-Type");The headers that are available by default are:
headers
- the values to be added to the 'Access-Control-Expose-Headers' response headerCorsConfigBuilder
to support method chaining.public CorsConfigBuilder exposeHeaders(CharSequence... headers)
xhr.getResponseHeader(HttpHeaderNames.CONTENT_TYPE);The headers that are available by default are:
headers
- the values to be added to the 'Access-Control-Expose-Headers' response headerCorsConfigBuilder
to support method chaining.public CorsConfigBuilder allowCredentials()
xhr.withCredentials = true;The default value for 'withCredentials' is false in which case no cookies are sent. Setting this to true will included cookies in cross origin requests.
CorsConfigBuilder
to support method chaining.public CorsConfigBuilder maxAge(long max)
max
- the maximum time, in seconds, that the preflight response may be cached.CorsConfigBuilder
to support method chaining.public CorsConfigBuilder allowedRequestMethods(HttpMethod... methods)
methods
- the HttpMethod
s that should be allowed.CorsConfigBuilder
to support method chaining.public CorsConfigBuilder allowedRequestHeaders(String... headers)
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 allow a request).
headers
- the headers to be added to the preflight 'Access-Control-Allow-Headers' response header.CorsConfigBuilder
to support method chaining.public CorsConfigBuilder allowedRequestHeaders(CharSequence... headers)
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 allow a request).
headers
- the headers to be added to the preflight 'Access-Control-Allow-Headers' response header.CorsConfigBuilder
to support method chaining.public CorsConfigBuilder preflightResponseHeader(CharSequence name, Object... values)
name
- the name of the HTTP header.values
- the values for the HTTP header.CorsConfigBuilder
to support method chaining.public <T> CorsConfigBuilder preflightResponseHeader(CharSequence name, Iterable<T> value)
T
- the type of values that the Iterable contains.name
- the name of the HTTP header.value
- the values for the HTTP header.CorsConfigBuilder
to support method chaining.public <T> CorsConfigBuilder preflightResponseHeader(CharSequence name, Callable<T> valueGenerator)
T
- the type of the value that the Callable can return.name
- the name of the HTTP header.valueGenerator
- a Callable which will be invoked at HTTP response creation.CorsConfigBuilder
to support method chaining.public CorsConfigBuilder noPreflightResponseHeaders()
CorsConfigBuilder
to support method chaining.public CorsConfigBuilder shortCircuit()
CorsConfigBuilder
to support method chaining.public CorsConfigBuilder allowPrivateNetwork()
CorsConfigBuilder
to support method chaining.public CorsConfig build()
CorsConfig
with settings specified by previous method calls.CorsConfig
the configured CorsConfig instance.Copyright © 2008–2024 The Netty Project. All rights reserved.