public static class CorsConfig.Builder
extends java.lang.Object
Constructor and Description |
---|
Builder()
Creates a new Builder instance allowing any origin, "*" which is the
wildcard origin.
|
Builder(java.lang.String... origins)
Creates a new Builder instance with the origin passed in.
|
Modifier and Type | Method and Description |
---|---|
CorsConfig.Builder |
allowCredentials()
By default cookies are not included in CORS requests, but this method will enable cookies to
be added to CORS requests.
|
CorsConfig.Builder |
allowedRequestHeaders(java.lang.String... headers)
Specifies the if headers that should be returned in the CORS 'Access-Control-Allow-Headers'
response header.
|
CorsConfig.Builder |
allowedRequestMethods(HttpMethod... methods)
Specifies the allowed set of HTTP Request Methods that should be returned in the
CORS 'Access-Control-Request-Method' response header.
|
CorsConfig.Builder |
allowNullOrigin()
Web browsers may set the 'Origin' request header to 'null' if a resource is loaded
from the local file system.
|
CorsConfig |
build()
Builds a
CorsConfig with settings specified by previous method calls. |
CorsConfig.Builder |
disable()
Disables CORS support.
|
CorsConfig.Builder |
exposeHeaders(java.lang.String... headers)
Specifies the headers to be exposed to calling clients.
|
CorsConfig.Builder |
maxAge(long max)
When making a preflight request the client has to perform two request with can be inefficient.
|
CorsConfig.Builder |
noPreflightResponseHeaders()
Specifies that no preflight response headers should be added to a preflight response.
|
<T> CorsConfig.Builder |
preflightResponseHeader(java.lang.CharSequence name,
java.lang.Iterable<T> value)
Returns HTTP response headers that should be added to a CORS preflight response.
|
CorsConfig.Builder |
preflightResponseHeader(java.lang.CharSequence name,
java.lang.Object... values)
Returns HTTP response headers that should be added to a CORS preflight response.
|
<T> CorsConfig.Builder |
preflightResponseHeader(java.lang.String name,
java.util.concurrent.Callable<T> valueGenerator)
Returns HTTP response headers that should be added to a CORS preflight response.
|
CorsConfig.Builder |
shortCurcuit()
Specifies that a CORS request should be rejected if it's invalid before being
further processing.
|
public Builder(java.lang.String... origins)
origins
- the origin to be used for this builder.public Builder()
public CorsConfig.Builder allowNullOrigin()
CorsConfig.Builder
to support method chaining.public CorsConfig.Builder disable()
CorsConfig.Builder
to support method chaining.public CorsConfig.Builder exposeHeaders(java.lang.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 headerCorsConfig.Builder
to support method chaining.public CorsConfig.Builder allowCredentials()
xhr.withCredentials = true;The default value for 'withCredentials' is false in which case no cookies are sent. Settning this to true will included cookies in cross origin requests.
CorsConfig.Builder
to support method chaining.public CorsConfig.Builder maxAge(long max)
max
- the maximum time, in seconds, that the preflight response may be cached.CorsConfig.Builder
to support method chaining.public CorsConfig.Builder allowedRequestMethods(HttpMethod... methods)
methods
- the HttpMethod
s that should be allowed.CorsConfig.Builder
to support method chaining.public CorsConfig.Builder allowedRequestHeaders(java.lang.String... headers)
xhr.setRequestHeader('My-Custom-Header', "SomeValue");the server will recieve 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.CorsConfig.Builder
to support method chaining.public CorsConfig.Builder preflightResponseHeader(java.lang.CharSequence name, java.lang.Object... values)
name
- the name of the HTTP header.values
- the values for the HTTP header.CorsConfig.Builder
to support method chaining.public <T> CorsConfig.Builder preflightResponseHeader(java.lang.CharSequence name, java.lang.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.CorsConfig.Builder
to support method chaining.public <T> CorsConfig.Builder preflightResponseHeader(java.lang.String name, java.util.concurrent.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.CorsConfig.Builder
to support method chaining.public CorsConfig.Builder noPreflightResponseHeaders()
CorsConfig.Builder
to support method chaining.public CorsConfig build()
CorsConfig
with settings specified by previous method calls.CorsConfig
the configured CorsConfig instance.public CorsConfig.Builder shortCurcuit()
CorsConfig.Builder
to support method chaining.Copyright © 2008–2018 The Netty Project. All rights reserved.