Package io.netty.handler.codec.http.cors
Class CorsConfig
- java.lang.Object
-
- io.netty.handler.codec.http.cors.CorsConfig
-
public final class CorsConfig extends java.lang.ObjectConfiguration for Cross-Origin Resource Sharing (CORS).
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classCorsConfig.BuilderDeprecated.UseCorsConfigBuilderinstead.static classCorsConfig.DateValueGeneratorDeprecated.Removed without alternatives.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description java.util.Set<java.lang.String>allowedRequestHeaders()Returns the allowed set of Request Headers.java.util.Set<HttpMethod>allowedRequestMethods()Returns the allowed set of Request Methods.java.util.Set<java.lang.String>exposedHeaders()Returns a set of headers to be exposed to calling clients.booleanisAnyOriginSupported()Determines whether a wildcard origin, '*', is supported.booleanisCorsSupportEnabled()Determines if support for CORS is enabled.booleanisCredentialsAllowed()Determines if cookies are supported for CORS requests.booleanisNullOriginAllowed()Web browsers may set the 'Origin' request header to 'null' if a resource is loaded from the local file system.booleanisPrivateNetworkAllowed()Web browsers may set the 'Access-Control-Request-Private-Network' request header if a resource is loaded from a local network.booleanisShortCircuit()Determines whether a CORS request should be rejected if it's invalid before being further processing.booleanisShortCurcuit()Deprecated.UseisShortCircuit()instead.longmaxAge()Gets the maxAge setting.java.lang.Stringorigin()Returns the allowed origin.java.util.Set<java.lang.String>origins()Returns the set of allowed origins.HttpHeaderspreflightResponseHeaders()Returns HTTP response headers that should be added to a CORS preflight response.java.lang.StringtoString()static CorsConfig.BuilderwithAnyOrigin()Deprecated.UseCorsConfigBuilder.forAnyOrigin()instead.static CorsConfig.BuilderwithOrigin(java.lang.String origin)Deprecated.UseCorsConfigBuilder.forOrigin(String)instead.static CorsConfig.BuilderwithOrigins(java.lang.String... origins)Deprecated.UseCorsConfigBuilder.forOrigins(String...)instead.
-
-
-
Method Detail
-
isCorsSupportEnabled
public boolean isCorsSupportEnabled()
Determines if support for CORS is enabled.- Returns:
trueif support for CORS is enabled, false otherwise.
-
isAnyOriginSupported
public boolean isAnyOriginSupported()
Determines whether a wildcard origin, '*', is supported.- Returns:
booleantrue if any origin is allowed.
-
origin
public java.lang.String origin()
Returns the allowed origin. This can either be a wildcard or an origin value.- Returns:
- the value that will be used for the CORS response header 'Access-Control-Allow-Origin'
-
origins
public java.util.Set<java.lang.String> origins()
Returns the set of allowed origins.- Returns:
Setthe allowed origins.
-
isNullOriginAllowed
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:
trueif a 'null' origin should be supported.
-
isPrivateNetworkAllowed
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:
trueif private network access should be allowed.
-
exposedHeaders
public java.util.Set<java.lang.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
- Returns:
List<String>a list of the headers to expose.
-
isCredentialsAllowed
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:
trueif cookies are supported.
-
maxAge
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:
longthe time in seconds that a preflight request may be cached.
-
allowedRequestMethods
public java.util.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:
SetofHttpMethods that represent the allowed Request Methods.
-
allowedRequestHeaders
public java.util.Set<java.lang.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>of strings that represent the allowed Request Headers.
-
preflightResponseHeaders
public HttpHeaders preflightResponseHeaders()
Returns HTTP response headers that should be added to a CORS preflight response.- Returns:
HttpHeadersthe HTTP response headers to be added.
-
isShortCircuit
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:
trueif a CORS request should short-circuit upon receiving an invalid Origin header.
-
isShortCurcuit
@Deprecated public boolean isShortCurcuit()
Deprecated.UseisShortCircuit()instead.
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
withAnyOrigin
@Deprecated public static CorsConfig.Builder withAnyOrigin()
Deprecated.UseCorsConfigBuilder.forAnyOrigin()instead.
-
withOrigin
@Deprecated public static CorsConfig.Builder withOrigin(java.lang.String origin)
Deprecated.UseCorsConfigBuilder.forOrigin(String)instead.
-
withOrigins
@Deprecated public static CorsConfig.Builder withOrigins(java.lang.String... origins)
Deprecated.UseCorsConfigBuilder.forOrigins(String...)instead.
-
-