Top Description Inners Fields Constructors Methods
io.netty.handler.codec.http.cors

public final Class CorsConfigBuilder

extends Object
Class Inheritance
Static Imports
io.netty.util.internal.ObjectUtil.checkNotNullWithIAE

Builder used to configure and build a CorsConfig instance.

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
CorsConfigBuilder.ConstantValueGenerator

This class is used for preflight HTTP response values that do not need to be generated, but instead the value is "static" in that the same value will be returned for each call.

private static class
CorsConfigBuilder.DateValueGenerator

This callable is used for the DATE preflight HTTP response HTTP header.

Field Summary

Modifier and TypeField and Description
pack-priv boolean
pack-priv boolean
pack-priv boolean
pack-priv final boolean
pack-priv boolean
pack-priv final Set<String>
pack-priv long
private boolean
pack-priv final Set<String>
pack-priv final Map<CharSequence, Callable<?>>
pack-priv final Set<String>
pack-priv final Set<HttpMethod>
pack-priv boolean

Constructor Summary

AccessConstructor and Description
pack-priv
CorsConfigBuilder(final String...
the origin to be used for this builder.
origins
)

Creates a new Builder instance with the origin passed in.

pack-priv
CorsConfigBuilder()

Creates a new Builder instance allowing any origin, "*" which is the wildcard origin.

Method Summary

Modifier and TypeMethod and Description
public CorsConfigBuilder

Returns:

CorsConfigBuilder to support method chaining.
allowCredentials
()

By default cookies are not included in CORS requests, but this method will enable cookies to be added to CORS requests.

public CorsConfigBuilder

Returns:

CorsConfigBuilder to support method chaining.
allowedRequestHeaders
(final String...
the headers to be added to the preflight 'Access-Control-Allow-Headers' response header.
headers
)

Specifies the if headers that should be returned in the CORS 'Access-Control-Allow-Headers' response header.

public CorsConfigBuilder

Returns:

CorsConfigBuilder to support method chaining.
allowedRequestHeaders
(final CharSequence...
the headers to be added to the preflight 'Access-Control-Allow-Headers' response header.
headers
)

Specifies the if headers that should be returned in the CORS 'Access-Control-Allow-Headers' response header.

public CorsConfigBuilder

Returns:

CorsConfigBuilder to support method chaining.
allowedRequestMethods
(final HttpMethod...
the HttpMethods that should be allowed.
methods
)

Specifies the allowed set of HTTP Request Methods that should be returned in the CORS 'Access-Control-Request-Method' response header.

public CorsConfigBuilder

Returns:

CorsConfigBuilder to support method chaining.
allowNullOrigin
()

Web browsers may set the 'Origin' request header to 'null' if a resource is loaded from the local file system.

public CorsConfigBuilder

Returns:

CorsConfigBuilder to support method chaining.
allowPrivateNetwork
()

Web browsers may set the 'Access-Control-Request-Private-Network' request header if a resource is loaded from a local network.

public CorsConfig

Returns:

CorsConfig the configured CorsConfig instance.
build
()

Builds a CorsConfig with settings specified by previous method calls.

public CorsConfigBuilder

Returns:

CorsConfigBuilder to support method chaining.
disable
()

Disables CORS support.

public CorsConfigBuilder

Returns:

CorsConfigBuilder to support method chaining.
exposeHeaders
(final String...
the values to be added to the 'Access-Control-Expose-Headers' response header
headers
)

Specifies the headers to be exposed to calling clients.

public CorsConfigBuilder

Returns:

CorsConfigBuilder to support method chaining.
exposeHeaders
(final CharSequence...
the values to be added to the 'Access-Control-Expose-Headers' response header
headers
)

Specifies the headers to be exposed to calling clients.

public static CorsConfigBuilder

Returns:

Builder to support method chaining.
forAnyOrigin
()

Creates a Builder instance with it's origin set to '*'.

public static CorsConfigBuilder

Returns:

CorsConfigBuilder to support method chaining.
forOrigin
(final String origin)

Creates a CorsConfigBuilder instance with the specified origin.

public static CorsConfigBuilder

Returns:

CorsConfigBuilder to support method chaining.
forOrigins
(final String... origins)

Creates a CorsConfigBuilder instance with the specified origins.

public CorsConfigBuilder

Returns:

CorsConfigBuilder to support method chaining.
maxAge
(final long
the maximum time, in seconds, that the preflight response may be cached.
max
)

When making a preflight request the client has to perform two request with can be inefficient.

public CorsConfigBuilder

Returns:

CorsConfigBuilder to support method chaining.
noPreflightResponseHeaders
()

Specifies that no preflight response headers should be added to a preflight response.

public CorsConfigBuilder

Returns:

CorsConfigBuilder to support method chaining.
preflightResponseHeader
(final CharSequence
the name of the HTTP header.
name
,
final Object...
the values for the HTTP header.
values
)

Returns HTTP response headers that should be added to a CORS preflight response.

public <
the type of values that the Iterable contains.
T
>
CorsConfigBuilder

Returns:

CorsConfigBuilder to support method chaining.
preflightResponseHeader
(final CharSequence
the name of the HTTP header.
name
,
final Iterable<T>
the values for the HTTP header.
value
)

Returns HTTP response headers that should be added to a CORS preflight response.

public <
the type of the value that the Callable can return.
T
>
CorsConfigBuilder

Returns:

CorsConfigBuilder to support method chaining.
preflightResponseHeader
(final CharSequence
the name of the HTTP header.
name
,
final Callable<T>
a Callable which will be invoked at HTTP response creation.
valueGenerator
)

Returns HTTP response headers that should be added to a CORS preflight response.

public CorsConfigBuilder

Returns:

CorsConfigBuilder to support method chaining.
shortCircuit
()

Specifies that a CORS request should be rejected if it's invalid before being further processing.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

allowCredentialsback to summary
pack-priv boolean allowCredentials
allowNullOriginback to summary
pack-priv boolean allowNullOrigin
allowPrivateNetworkback to summary
pack-priv boolean allowPrivateNetwork
anyOriginback to summary
pack-priv final boolean anyOrigin
enabledback to summary
pack-priv boolean enabled
exposeHeadersback to summary
pack-priv final Set<String> exposeHeaders
maxAgeback to summary
pack-priv long maxAge
noPreflightHeadersback to summary
private boolean noPreflightHeaders
originsback to summary
pack-priv final Set<String> origins
preflightHeadersback to summary
pack-priv final Map<CharSequence, Callable<?>> preflightHeaders
requestHeadersback to summary
pack-priv final Set<String> requestHeaders
requestMethodsback to summary
pack-priv final Set<HttpMethod> requestMethods
shortCircuitback to summary
pack-priv boolean shortCircuit

Constructor Detail

CorsConfigBuilderback to summary
pack-priv CorsConfigBuilder(final String... origins)

Creates a new Builder instance with the origin passed in.

Parameters
origins:String[]

the origin to be used for this builder.

CorsConfigBuilderback to summary
pack-priv CorsConfigBuilder()

Creates a new Builder instance allowing any origin, "*" which is the wildcard origin.

Method Detail

allowCredentialsback to summary
public CorsConfigBuilder allowCredentials()

By default cookies are not included in CORS requests, but this method will enable cookies to be added to CORS requests. Calling this method 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 included cookies in cross origin requests.
Returns:CorsConfigBuilder

CorsConfigBuilder to support method chaining.

allowedRequestHeadersback to summary
public CorsConfigBuilder allowedRequestHeaders(final String... headers)

Specifies the if headers that should be returned in the CORS '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 allow a request).
Parameters
headers:String[]

the headers to be added to the preflight 'Access-Control-Allow-Headers' response header.

Returns:CorsConfigBuilder

CorsConfigBuilder to support method chaining.

allowedRequestHeadersback to summary
public CorsConfigBuilder allowedRequestHeaders(final CharSequence... headers)

Specifies the if headers that should be returned in the CORS '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 allow a request).
Parameters
headers:CharSequence[]

the headers to be added to the preflight 'Access-Control-Allow-Headers' response header.

Returns:CorsConfigBuilder

CorsConfigBuilder to support method chaining.

allowedRequestMethodsback to summary
public CorsConfigBuilder allowedRequestMethods(final HttpMethod... methods)

Specifies the allowed set of HTTP Request Methods that should be returned in the CORS 'Access-Control-Request-Method' response header.

Parameters
methods:HttpMethod[]

the HttpMethods that should be allowed.

Returns:CorsConfigBuilder

CorsConfigBuilder to support method chaining.

allowNullOriginback to summary
public CorsConfigBuilder allowNullOrigin()

Web browsers may set the 'Origin' request header to 'null' if a resource is loaded from the local file system. Calling this method will enable a successful CORS response with a "null" value for the CORS response header 'Access-Control-Allow-Origin'.

Returns:CorsConfigBuilder

CorsConfigBuilder to support method chaining.

allowPrivateNetworkback to summary
public CorsConfigBuilder allowPrivateNetwork()

Web browsers may set the 'Access-Control-Request-Private-Network' request header if a resource is loaded from a local network. By default direct access to private network endpoints from public websites is not allowed. Calling this method will set the CORS 'Access-Control-Request-Private-Network' response header to true.

Returns:CorsConfigBuilder

CorsConfigBuilder to support method chaining.

buildback to summary
public CorsConfig build()

Builds a CorsConfig with settings specified by previous method calls.

Returns:CorsConfig

CorsConfig the configured CorsConfig instance.

disableback to summary
public CorsConfigBuilder disable()

Disables CORS support.

Returns:CorsConfigBuilder

CorsConfigBuilder to support method chaining.

exposeHeadersback to summary
public CorsConfigBuilder exposeHeaders(final String... headers)

Specifies the headers to be exposed to calling clients. 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-Control
  • Content-Language
  • Content-Type
  • Expires
  • Last-Modified
  • Pragma
To 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.
Parameters
headers:String[]

the values to be added to the 'Access-Control-Expose-Headers' response header

Returns:CorsConfigBuilder

CorsConfigBuilder to support method chaining.

exposeHeadersback to summary
public CorsConfigBuilder exposeHeaders(final CharSequence... headers)

Specifies the headers to be exposed to calling clients. During a simple CORS request, only certain response headers are made available by the browser, for example using:

xhr.getResponseHeader(HttpHeaderNames.CONTENT_TYPE);
The headers that are available by default are:
  • Cache-Control
  • Content-Language
  • Content-Type
  • Expires
  • Last-Modified
  • Pragma
To 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.
Parameters
headers:CharSequence[]

the values to be added to the 'Access-Control-Expose-Headers' response header

Returns:CorsConfigBuilder

CorsConfigBuilder to support method chaining.

forAnyOriginback to summary
public static CorsConfigBuilder forAnyOrigin()

Creates a Builder instance with it's origin set to '*'.

Returns:CorsConfigBuilder

Builder to support method chaining.

forOriginback to summary
public static CorsConfigBuilder forOrigin(final String origin)

Creates a CorsConfigBuilder instance with the specified origin.

Returns:CorsConfigBuilder

CorsConfigBuilder to support method chaining.

forOriginsback to summary
public static CorsConfigBuilder forOrigins(final String... origins)

Creates a CorsConfigBuilder instance with the specified origins.

Returns:CorsConfigBuilder

CorsConfigBuilder to support method chaining.

maxAgeback to summary
public CorsConfigBuilder maxAge(final long max)

When making a preflight request the client has to perform two request with can be inefficient. This setting will set the CORS '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.

Parameters
max:long

the maximum time, in seconds, that the preflight response may be cached.

Returns:CorsConfigBuilder

CorsConfigBuilder to support method chaining.

noPreflightResponseHeadersback to summary
public CorsConfigBuilder noPreflightResponseHeaders()

Specifies that no preflight response headers should be added to a preflight response.

Returns:CorsConfigBuilder

CorsConfigBuilder to support method chaining.

preflightResponseHeaderback to summary
public CorsConfigBuilder preflightResponseHeader(final CharSequence name, final Object... values)

Returns HTTP response headers that should be added to a CORS preflight response. An intermediary like a load balancer might require that a CORS preflight request have certain headers set. This enables such headers to be added.

Parameters
name:CharSequence

the name of the HTTP header.

values:Object[]

the values for the HTTP header.

Returns:CorsConfigBuilder

CorsConfigBuilder to support method chaining.

preflightResponseHeaderback to summary
public <T> CorsConfigBuilder preflightResponseHeader(final CharSequence name, final Iterable<T> value)

Returns HTTP response headers that should be added to a CORS preflight response. An intermediary like a load balancer might require that a CORS preflight request have certain headers set. This enables such headers to be added.

Parameters
<T>
the type of values that the Iterable contains.
name:CharSequence

the name of the HTTP header.

value:Iterable<T>

the values for the HTTP header.

Returns:CorsConfigBuilder

CorsConfigBuilder to support method chaining.

preflightResponseHeaderback to summary
public <T> CorsConfigBuilder preflightResponseHeader(final CharSequence name, final Callable<T> valueGenerator)

Returns HTTP response headers that should be added to a CORS preflight response. 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 Callable which will have its 'call' method invoked when the HTTP response is created.

Parameters
<T>
the type of the value that the Callable can return.
name:CharSequence

the name of the HTTP header.

valueGenerator:Callable<T>

a Callable which will be invoked at HTTP response creation.

Returns:CorsConfigBuilder

CorsConfigBuilder to support method chaining.

shortCircuitback to summary
public CorsConfigBuilder shortCircuit()

Specifies that a CORS request should be rejected if it's invalid before being further processing. CORS headers are set after a request is processed. This may not always be desired and this setting will check that the Origin is valid and if it is not valid no further processing will take place, and an error will be returned to the calling client.

Returns:CorsConfigBuilder

CorsConfigBuilder to support method chaining.

io.netty.handler.codec.http.cors back to summary

private final Class CorsConfigBuilder.ConstantValueGenerator

extends Object
implements Callable<Object>
Class Inheritance
  • java.lang.Object
  • io.netty.handler.codec.http.cors.CorsConfigBuilder.ConstantValueGenerator
All Implemented Interfaces
java.util.concurrent.Callable

This class is used for preflight HTTP response values that do not need to be generated, but instead the value is "static" in that the same value will be returned for each call.

Field Summary

Modifier and TypeField and Description
private final Object

Constructor Summary

AccessConstructor and Description
private
ConstantValueGenerator(final Object
the value that will be returned when the call method is invoked.
value
)

Sole constructor.

Method Summary

Modifier and TypeMethod and Description
public Object
call()

Implements java.util.concurrent.Callable.call.

Computes a result, or throws an exception if unable to do so.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

valueback to summary
private final Object value

Constructor Detail

ConstantValueGeneratorback to summary
private ConstantValueGenerator(final Object value)

Sole constructor.

Parameters
value:Object

the value that will be returned when the call method is invoked.

Method Detail

callback to summary
public Object call()

Implements java.util.concurrent.Callable.call.

Doc from java.util.concurrent.Callable.call.

Computes a result, or throws an exception if unable to do so.

Returns:Object

computed result

Annotations
@Override
io.netty.handler.codec.http.cors back to summary

private final Class CorsConfigBuilder.DateValueGenerator

extends Object
implements Callable<Date>
Class Inheritance
  • java.lang.Object
  • io.netty.handler.codec.http.cors.CorsConfigBuilder.DateValueGenerator
All Implemented Interfaces
java.util.concurrent.Callable

This callable is used for the DATE preflight HTTP response HTTP header. It's value must be generated when the response is generated, hence will be different for every call.

Field Summary

Modifier and TypeField and Description
pack-priv static final CorsConfigBuilder.DateValueGenerator

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public Date
call()

Implements java.util.concurrent.Callable.call.

Computes a result, or throws an exception if unable to do so.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

INSTANCEback to summary
pack-priv static final CorsConfigBuilder.DateValueGenerator INSTANCE

Constructor Detail

DateValueGeneratorback to summary
private DateValueGenerator()

Method Detail

callback to summary
public Date call() throws Exception

Implements java.util.concurrent.Callable.call.

Doc from java.util.concurrent.Callable.call.

Computes a result, or throws an exception if unable to do so.

Returns:Date

computed result

Annotations
@Override
Exceptions
Exception:
if unable to compute a result