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

public final Class CorsConfig

extends Object
Class Inheritance
Imports
io.netty.handler.codec.http.DefaultHttpHeaders, .EmptyHttpHeaders, .HttpHeaders, .HttpMethod, io.netty.util.internal.StringUtil, java.util.Collections, .Date, .LinkedHashSet, .Map, .Map.Entry, .Set, java.util.concurrent.Callable

Configuration for Cross-Origin Resource Sharing (CORS).

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static class
CorsConfig.Builder

Deprecated Use CorsConfigBuilder instead.
public static class
CorsConfig.DateValueGenerator

Deprecated Removed without alternatives.

Field Summary

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

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
public Set<String>

Returns:

Set<String> of strings that represent the allowed Request Headers.
allowedRequestHeaders
()

Returns the allowed set of Request Headers.

public Set<HttpMethod>

Returns:

Set of HttpMethods that represent the allowed Request Methods.
allowedRequestMethods
()

Returns the allowed set of Request Methods.

public Set<String>

Returns:

List<String> a list of the headers to expose.
exposedHeaders
()

Returns a set of headers to be exposed to calling clients.

private static <T> T
getValue(final Callable<T> callable)

public boolean

Returns:

boolean true if any origin is allowed.
isAnyOriginSupported
()

Determines whether a wildcard origin, '*', is supported.

public boolean

Returns:

true if support for CORS is enabled, false otherwise.
isCorsSupportEnabled
()

Determines if support for CORS is enabled.

public boolean

Returns:

true if cookies are supported.
isCredentialsAllowed
()

Determines if cookies are supported for CORS requests.

public boolean

Returns:

true if a 'null' origin should be supported.
isNullOriginAllowed
()

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

public boolean

Returns:

true if private network access should be allowed.
isPrivateNetworkAllowed
()

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

public boolean

Returns:

true if a CORS request should short-circuit upon receiving an invalid Origin header.
isShortCircuit
()

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

public boolean
isShortCurcuit()

Deprecated Use isShortCircuit() instead.
public long

Returns:

long the time in seconds that a preflight request may be cached.
maxAge
()

Gets the maxAge setting.

public String

Returns:

the value that will be used for the CORS response header 'Access-Control-Allow-Origin'
origin
()

Returns the allowed origin.

public Set<String>

Returns:

Set the allowed origins.
origins
()

Returns the set of allowed origins.

public HttpHeaders

Returns:

HttpHeaders the HTTP response headers to be added.
preflightResponseHeaders
()

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

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.
public static CorsConfig.Builder
public static CorsConfig.Builder
withOrigin(final String origin)

Deprecated Use CorsConfigBuilder#forOrigin(String) instead.
public static CorsConfig.Builder
withOrigins(final String... origins)

Deprecated Use CorsConfigBuilder#forOrigins(String...) instead.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

allowCredentialsback to summary
private final boolean allowCredentials
allowedRequestHeadersback to summary
private final Set<String> allowedRequestHeaders
allowedRequestMethodsback to summary
private final Set<HttpMethod> allowedRequestMethods
allowNullOriginback to summary
private final boolean allowNullOrigin
allowPrivateNetworkback to summary
private final boolean allowPrivateNetwork
anyOriginback to summary
private final boolean anyOrigin
enabledback to summary
private final boolean enabled
exposeHeadersback to summary
private final Set<String> exposeHeaders
maxAgeback to summary
private final long maxAge
originsback to summary
private final Set<String> origins
preflightHeadersback to summary
private final Map<CharSequence, Callable<?>> preflightHeaders
shortCircuitback to summary
private final boolean shortCircuit

Constructor Detail

CorsConfigback to summary
pack-priv CorsConfig(final CorsConfigBuilder builder)

Method Detail

allowedRequestHeadersback to summary
public Set<String> allowedRequestHeaders()

Returns the allowed set of Request Headers. The header names returned from this method will be used to set the CORS 'Access-Control-Allow-Headers' response header.

Returns:Set<String>

Set<String> of strings that represent the allowed Request Headers.

allowedRequestMethodsback to summary
public Set<HttpMethod> allowedRequestMethods()

Returns the allowed set of Request Methods. The Http methods that should be returned in the CORS 'Access-Control-Request-Method' response header.

Returns:Set<HttpMethod>

Set of HttpMethods that represent the allowed Request Methods.

exposedHeadersback to summary
public Set<String> exposedHeaders()

Returns a set of 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 names to the CORS 'Access-Control-Expose-Headers' response header.
Returns:Set<String>

List<String> a list of the headers to expose.

getValueback to summary
private static <T> T getValue(final Callable<T> callable)
isAnyOriginSupportedback to summary
public boolean isAnyOriginSupported()

Determines whether a wildcard origin, '*', is supported.

Returns:boolean

boolean true if any origin is allowed.

isCorsSupportEnabledback to summary
public boolean isCorsSupportEnabled()

Determines if support for CORS is enabled.

Returns:boolean

true if support for CORS is enabled, false otherwise.

isCredentialsAllowedback to summary
public boolean isCredentialsAllowed()

Determines if cookies are supported for CORS requests. 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 included cookies in cross origin requests.
Returns:boolean

true if cookies are supported.

isNullOriginAllowedback to summary
public boolean isNullOriginAllowed()

Web browsers may set the 'Origin' request header to 'null' if a resource is loaded from the local file system. If isNullOriginAllowed is true then the server will response with the wildcard for the CORS response header 'Access-Control-Allow-Origin'.

Returns:boolean

true if a 'null' origin should be supported.

isPrivateNetworkAllowedback to summary
public boolean isPrivateNetworkAllowed()

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. If isPrivateNetworkAllowed is true the server will response with the CORS response header 'Access-Control-Request-Private-Network'.

Returns:boolean

true if private network access should be allowed.

isShortCircuitback to summary
public boolean isShortCircuit()

Determines whether 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:boolean

true if a CORS request should short-circuit upon receiving an invalid Origin header.

isShortCurcuitback to summary
public boolean isShortCurcuit()

Deprecated

Use isShortCircuit() instead.

Annotations
@Deprecated
maxAgeback to summary
public long maxAge()

Gets the maxAge setting. 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.

Returns:long

long the time in seconds that a preflight request may be cached.

originback to summary
public String origin()

Returns the allowed origin. This can either be a wildcard or an origin value.

Returns:String

the value that will be used for the CORS response header 'Access-Control-Allow-Origin'

originsback to summary
public Set<String> origins()

Returns the set of allowed origins.

Returns:Set<String>

Set the allowed origins.

preflightResponseHeadersback to summary
public HttpHeaders preflightResponseHeaders()

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

Returns:HttpHeaders

HttpHeaders the HTTP response headers to be added.

toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object.

Returns:String

a string representation of the object.

Annotations
@Override
withAnyOriginback to summary
public static CorsConfig.Builder withAnyOrigin()

Deprecated

Use CorsConfigBuilder#forAnyOrigin() instead.

Annotations
@Deprecated
withOriginback to summary
public static CorsConfig.Builder withOrigin(final String origin)

Deprecated

Use CorsConfigBuilder#forOrigin(String) instead.

Annotations
@Deprecated
withOriginsback to summary
public static CorsConfig.Builder withOrigins(final String... origins)
Annotations
@Deprecated
io.netty.handler.codec.http.cors back to summary

public Class CorsConfig.Builder

extends Object
Class Inheritance
Annotations
@Deprecated

Deprecated

Use CorsConfigBuilder instead.

Field Summary

Modifier and TypeField and Description
private final CorsConfigBuilder

Constructor Summary

AccessConstructor and Description
public
Builder(final String... origins)

Deprecated Use CorsConfigBuilder instead.
public
Builder()

Deprecated Use CorsConfigBuilder instead.

Method Summary

Modifier and TypeMethod and Description
public CorsConfig.Builder
public CorsConfig.Builder
public CorsConfig.Builder
public CorsConfig.Builder
public CorsConfig
build()

Deprecated Use CorsConfigBuilder#build() instead.
public CorsConfig.Builder
disable()

Deprecated Use CorsConfigBuilder#disable() instead.
public CorsConfig.Builder
exposeHeaders(final String... headers)

public CorsConfig.Builder
maxAge(final long max)

Deprecated Use CorsConfigBuilder#maxAge(long) instead.
public CorsConfig.Builder
public CorsConfig.Builder
public <T> CorsConfig.Builder
public <T> CorsConfig.Builder
public CorsConfig.Builder
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

builderback to summary
private final CorsConfigBuilder builder

Constructor Detail

Builderback to summary
public Builder(final String... origins)

Deprecated

Use CorsConfigBuilder instead.

Annotations
@Deprecated
Builderback to summary
public Builder()

Deprecated

Use CorsConfigBuilder instead.

Annotations
@Deprecated

Method Detail

allowCredentialsback to summary
public CorsConfig.Builder allowCredentials()

Deprecated

Use CorsConfigBuilder#allowCredentials() instead.

Annotations
@Deprecated
allowedRequestHeadersback to summary
public CorsConfig.Builder allowedRequestHeaders(final String... headers)
Annotations
@Deprecated
allowedRequestMethodsback to summary
public CorsConfig.Builder allowedRequestMethods(final HttpMethod... methods)
Annotations
@Deprecated
allowNullOriginback to summary
public CorsConfig.Builder allowNullOrigin()

Deprecated

Use CorsConfigBuilder#allowNullOrigin() instead.

Annotations
@Deprecated
buildback to summary
public CorsConfig build()

Deprecated

Use CorsConfigBuilder#build() instead.

Annotations
@Deprecated
disableback to summary
public CorsConfig.Builder disable()

Deprecated

Use CorsConfigBuilder#disable() instead.

Annotations
@Deprecated
exposeHeadersback to summary
public CorsConfig.Builder exposeHeaders(final String... headers)
Annotations
@Deprecated
maxAgeback to summary
public CorsConfig.Builder maxAge(final long max)

Deprecated

Use CorsConfigBuilder#maxAge(long) instead.

Annotations
@Deprecated
noPreflightResponseHeadersback to summary
public CorsConfig.Builder noPreflightResponseHeaders()
Annotations
@Deprecated
preflightResponseHeaderback to summary
public CorsConfig.Builder preflightResponseHeader(final CharSequence name, final Object... values)
Annotations
@Deprecated
preflightResponseHeaderback to summary
public <T> CorsConfig.Builder preflightResponseHeader(final CharSequence name, final Iterable<T> value)
Annotations
@Deprecated
preflightResponseHeaderback to summary
public <T> CorsConfig.Builder preflightResponseHeader(final String name, final Callable<T> valueGenerator)
Annotations
@Deprecated
shortCurcuitback to summary
public CorsConfig.Builder shortCurcuit()

Deprecated

Use CorsConfigBuilder#shortCircuit() instead.

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

public final Class CorsConfig.DateValueGenerator

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

Deprecated

Removed without alternatives.

Constructor Summary

AccessConstructor and Description
public

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

Constructor Detail

DateValueGeneratorback to summary
public 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