public class Cors extends Object
| Modifier and Type | Class and Description |
|---|---|
static class |
Cors.RequestHeader |
static class |
Cors.ResponseHeader |
| Modifier and Type | Field and Description |
|---|---|
private CorsConfiguration |
corsConfig |
private javax.servlet.http.HttpServletRequest |
request |
| Constructor and Description |
|---|
Cors(CorsConfiguration corsConfig,
javax.servlet.http.HttpServletRequest request)
Sole constructor.
|
| Modifier and Type | Method and Description |
|---|---|
boolean |
areRequestHeadersValid()
Checks that the configured preflight request headers (
Cors.RequestHeader.HEADERS) are supported according to the
underlying CorsConfiguration settings. |
boolean |
areRequestHeadersValid(List<String> validHeaders)
Checks that the preflight request headers (
Cors.RequestHeader.HEADERS) are supported. |
private String |
asString(Collection<String> strings) |
boolean |
canHandleRequest()
Determines if this instance can handle CORS requests.
|
List<String> |
getAllowedRequestHeaders()
Returns the allowed set of Request Headers.
|
Set<String> |
getAllowedRequestMethods()
Returns the allowed set of Request Methods.
|
String |
getRequestHeaders()
Returns the
Cors.RequestHeader.HEADERS request header. |
String |
getRequestMethod()
Returns the
Cors.RequestHeader.METHOD request header. |
private boolean |
hasHeader(String name) |
boolean |
hasOriginHeader()
Determines if the current
HttpServletRequest has an 'Origin' request header. |
boolean |
hasRequestHeaders()
Determines if the current
HttpServletRequest has a Cors.RequestHeader.HEADERS request header. |
boolean |
isCorsRequest()
Determines if the current
HttpServletRequest is a CORS request. |
boolean |
isCorsSupportEnabled()
Determines if core support has been enabled by the
CorsConfig instance. |
boolean |
isOptionsMethod()
Determines if the the current
HttpServletRequest's http method is 'OPTIONS'. |
boolean |
isPreflightRequest()
Determines if the current
HttpServletRequest qualifies as a 'Preflight' request. |
boolean |
isRequestMethodValid()
Checks that the preflight request method (
Cors.RequestHeader.METHOD) is supported according to the
CorsConfiguration settings. |
boolean |
isRequestMethodValid(Set<String> validMethods)
Checks that the preflight request method (
Cors.RequestHeader.METHOD) is supported. |
Cors |
setAllowCredentials(javax.servlet.http.HttpServletResponse response)
Set the
Cors.ResponseHeader.ALLOW_CREDENTIALS to 'true' if allowCookies was set set to true in the underlying
CorsConfiguration. |
Cors |
setAllowHeaders(javax.servlet.http.HttpServletResponse response)
Set the
Cors.ResponseHeader.ALLOW_HEADERS to configured values. |
Cors |
setAllowMethods(javax.servlet.http.HttpServletResponse response)
Set the
Cors.ResponseHeader.ALLOW_METHODS to the the configured comma separated list of http methods. |
Cors |
setAnyOrigin(javax.servlet.http.HttpServletResponse response)
Set the
Cors.ResponseHeader.ALLOW_ORIGIN to '*'. |
Cors |
setEchoOrigin(javax.servlet.http.HttpServletResponse response)
Set the
Cors.ResponseHeader.ALLOW_ORIGIN to be the same value that was passed in the 'Origin' request header. |
Cors |
setExposeHeaders(javax.servlet.http.HttpServletResponse response)
Set the
Cors.ResponseHeader.EXPOSE_HEADERS to the the configured comma separated list of headers. |
Cors |
setMaxAge(javax.servlet.http.HttpServletResponse response)
Set the
Cors.ResponseHeader.MAX_AGE to the configured max age value. |
Cors |
setOrigin(javax.servlet.http.HttpServletResponse response)
Set the
Cors.ResponseHeader.ALLOW_ORIGIN to either echo the 'Origin' or to support '*' depending on the underlying
CorsConfiguration setting. |
Cors |
setOrigin(javax.servlet.http.HttpServletResponse response,
String origin)
Set the
Cors.ResponseHeader.ALLOW_ORIGIN to the passed in value. |
private final javax.servlet.http.HttpServletRequest request
private final CorsConfiguration corsConfig
public Cors(CorsConfiguration corsConfig, javax.servlet.http.HttpServletRequest request)
corsConfig - The CorsConfig containing configuration options.request - The HttpServletRequest that this instance will use.public boolean isCorsRequest()
HttpServletRequest is a CORS request.
See http-origin section of the specification.true if the current request has an 'Origin' request header, otherwise false.public boolean canHandleRequest()
isCorsSupportEnabled()
&& isCorsRequest()true is CORS support has been enabled and if the current request is a CORS request.public boolean isCorsSupportEnabled()
CorsConfig instance.true if support for CORS is enabled.public boolean hasOriginHeader()
HttpServletRequest has an 'Origin' request header.true if the current request has an 'Origin' request header, otherwise false.public boolean isOptionsMethod()
HttpServletRequest's http method is 'OPTIONS'.true if the current request' http method is 'OPTIONS', otherwise false.public boolean isPreflightRequest()
HttpServletRequest qualifies as a 'Preflight' request.
See preflight-request section of the specification.true if the current request qualifies as a preflight, otherwise false.public boolean isRequestMethodValid(Set<String> validMethods)
Cors.RequestHeader.METHOD) is supported.validMethods - a set of methods that are allowed.true if the current request method is one of the allowed http methods.public boolean isRequestMethodValid()
Cors.RequestHeader.METHOD) is supported according to the
CorsConfiguration settings.true if the current request method is one of the allowed http methods.public boolean hasRequestHeaders()
HttpServletRequest has a Cors.RequestHeader.HEADERS request header.true if the current request methods has a RequestHeader.HEADERS header.public String getRequestHeaders()
Cors.RequestHeader.HEADERS request header.String if the current request methods has a RequestHeader.HEADERS header.public String getRequestMethod()
Cors.RequestHeader.METHOD request header.true if the current request methods has a RequestHeader.HEADERS header.public Set<String> getAllowedRequestMethods()
Set of allowed Request Methods.public List<String> getAllowedRequestHeaders()
Set of allowed Request Headers.public Cors setEchoOrigin(javax.servlet.http.HttpServletResponse response)
Cors.ResponseHeader.ALLOW_ORIGIN to be the same value that was passed in the 'Origin' request header.response - the HttpServletResponse for which the response header ResponseHeader.ALLOW_ORIGIN should be set.Cors to support methods chaining.public Cors setOrigin(javax.servlet.http.HttpServletResponse response)
Cors.ResponseHeader.ALLOW_ORIGIN to either echo the 'Origin' or to support '*' depending on the underlying
CorsConfiguration setting.response - the HttpServletResponse for which the response header ResponseHeader.ALLOW_ORIGIN should be set.Cors to support methods chaining.public Cors setOrigin(javax.servlet.http.HttpServletResponse response, String origin)
Cors.ResponseHeader.ALLOW_ORIGIN to the passed in value.response - the HttpServletResponse for which the response header ResponseHeader.ALLOW_ORIGIN should be set.Cors to support methods chaining.public Cors setAnyOrigin(javax.servlet.http.HttpServletResponse response)
Cors.ResponseHeader.ALLOW_ORIGIN to '*'.response - the HttpServletResponse for which the response header ResponseHeader.ALLOW_ORIGIN should be set.Cors to support methods chaining.public Cors setAllowCredentials(javax.servlet.http.HttpServletResponse response)
Cors.ResponseHeader.ALLOW_CREDENTIALS to 'true' if allowCookies was set set to true in the underlying
CorsConfiguration. By default cookies are not included in CORS requests but by setting this header cookies
will be added to CORS request.response - the HttpServletResponse for which the response header ResponseHeader.ALLOW_CREDENTIALS should be
set.Cors to support methods chaining.public Cors setExposeHeaders(javax.servlet.http.HttpServletResponse response)
Cors.ResponseHeader.EXPOSE_HEADERS to the the configured comma separated list of headers.
During a simple CORS request only certain response headers are made available to a calling client:
response - the HttpServletResponse for which the response header ResponseHeader#EXPOSE_HEADERS should be
set.Cors to support methods chaining.public Cors setAllowMethods(javax.servlet.http.HttpServletResponse response)
Cors.ResponseHeader.ALLOW_METHODS to the the configured comma separated list of http methods.response - the HttpServletResponse for which the response header ResponseHeader.ALLOW_METHODS should be set.Cors to support methods chaining.public Cors setMaxAge(javax.servlet.http.HttpServletResponse response)
Cors.ResponseHeader.MAX_AGE to the configured max age value.
When making a preflight request the client has to perform two request with can be inefficient. This setting enables
the caching of the preflight response for the specified time. During this time no preflight request will be made.
response - the HttpServletResponse for which the response header ResponseHeader.MAX_AGE should be set.Cors to support methods chaining.public boolean areRequestHeadersValid(List<String> validHeaders)
Cors.RequestHeader.HEADERS) are supported.validHeaders - a set of headers that are allowed.true if the current request headers are supported.public boolean areRequestHeadersValid()
Cors.RequestHeader.HEADERS) are supported according to the
underlying CorsConfiguration settings.true if the current request headers are not supported.public Cors setAllowHeaders(javax.servlet.http.HttpServletResponse response)
Cors.ResponseHeader.ALLOW_HEADERS to configured values.Cors to support methods chaining.private String asString(Collection<String> strings)
private boolean hasHeader(String name)
Copyright © 2013 JBoss, a division of Red Hat, Inc.. All Rights Reserved.