public class CorsResponseHelper extends Object
Modifier and Type | Field and Description |
---|---|
boolean |
allowAllRequestedHeaders
If true, copies the value of 'Access-Control-Request-Headers' request
header into the 'Access-Control-Allow-Headers' response header.
|
boolean |
allowedCredentials
If true, add 'Access-Control-Allow-Credentials' header.
|
Set<String> |
allowedHeaders
The value of 'Access-Control-Allow-Headers' response header.
|
Set<String> |
allowedOrigins
The value of 'Access-Control-Allow-Origin' header.
|
Set<String> |
exposedHeaders
The value of 'Access-Control-Expose-Headers' response header.
|
Constructor and Description |
---|
CorsResponseHelper() |
Modifier and Type | Method and Description |
---|---|
void |
addCorsResponseHeaders(Request request,
Response response)
Adds CORS headers to the given response.
|
Set<String> |
getAllowedHeaders()
Returns the modifiable set of headers allowed by the actual request on
the current resource.
Note that when used with HTTP connectors, this property maps to the "Access-Control-Allow-Headers" header. |
Set<String> |
getAllowedOrigins()
Returns the URI an origin server allows for the requested resource.
|
Set<String> |
getExposedHeaders()
Returns a modifiable whitelist of headers an origin server allows for the
requested resource.
Note that when used with HTTP connectors, this property maps to the "Access-Control-Expose-Headers" header. |
boolean |
isAllowAllRequestedHeaders()
If true, indicates that the value of 'Access-Control-Request-Headers'
request header will be copied into the 'Access-Control-Allow-Headers'
response header.
|
boolean |
isAllowedCredentials()
If true, adds 'Access-Control-Allow-Credentials' header.
|
boolean |
isCorsRequest(Request request)
Returns true if the request is a CORS request.
|
void |
setAllowAllRequestedHeaders(boolean allowAllRequestedHeaders)
If true, copies the value of 'Access-Control-Request-Headers' request
header into the 'Access-Control-Allow-Headers' response header.
|
void |
setAllowedCredentials(boolean allowedCredentials)
If true, adds 'Access-Control-Allow-Credentials' header.
|
void |
setAllowedHeaders(Set<String> allowedHeaders)
Sets the value of the 'Access-Control-Allow-Headers' response header.
|
void |
setAllowedOrigins(Set<String> allowedOrigins)
Sets the value of 'Access-Control-Allow-Origin' header.
|
void |
setExposedHeaders(Set<String> exposedHeaders)
Sets the value of 'Access-Control-Expose-Headers' response header.
|
public boolean allowAllRequestedHeaders
allowedHeaders
. Default is true.public boolean allowedCredentials
public Set<String> allowedHeaders
allowAllRequestedHeaders
is false.public Set<String> allowedOrigins
public void addCorsResponseHeaders(Request request, Response response)
request
- The current request.response
- The response.public Set<String> getAllowedHeaders()
public Set<String> getAllowedOrigins()
public Set<String> getExposedHeaders()
public boolean isAllowAllRequestedHeaders()
allowedHeaders
.public boolean isAllowedCredentials()
public boolean isCorsRequest(Request request)
request
- The current request.public void setAllowAllRequestedHeaders(boolean allowAllRequestedHeaders)
allowedHeaders
.allowAllRequestedHeaders
- True to copy the value of 'Access-Control-Request-Headers'
request header into the 'Access-Control-Allow-Headers'
response header. If false, use allowedHeaders
.public void setAllowedCredentials(boolean allowedCredentials)
allowedCredentials
- True to add the 'Access-Control-Allow-Credentials' header.public void setAllowedHeaders(Set<String> allowedHeaders)
allowAllRequestedHeaders
is false.allowedHeaders
- The value of 'Access-Control-Allow-Headers' response header.public void setAllowedOrigins(Set<String> allowedOrigins)
allowedOrigins
- The value of 'Access-Control-Allow-Origin' header.Copyright © 2005–2015. All rights reserved.