public class CorsService extends Service
CorsService corsService = new CorsService(); corsService.setAllowedOrigins(new HashSet(Arrays.asList("http://server.com"))); corsService.setAllowedCredentials(true);
Constructor and Description |
---|
CorsService()
Constructor.
|
CorsService(boolean enabled)
Constructor.
|
Modifier and Type | Method and Description |
---|---|
Filter |
createInboundFilter(Context context)
Create the filter that should be invoked for incoming calls.
|
java.util.Set<java.lang.String> |
getAllowedHeaders()
Returns the modifiable set of headers allowed by the actual request on
the current resource.
|
java.util.Set<java.lang.String> |
getAllowedOrigins()
Returns the URI an origin server allows for the requested resource.
|
java.util.Set<Method> |
getDefaultAllowedMethods()
Returns the list of methods allowed by default, used when
skippingResourceForCorsOptions is turned on. |
java.util.Set<java.lang.String> |
getExposedHeaders()
Returns a modifiable whitelist of headers an origin server allows for the
requested resource.
|
int |
getMaxAge()
Indicates how long (in seconds) the results of a preflight request can be cached in a preflight result cache.
|
boolean |
isAllowedCredentials()
If true, adds 'Access-Control-Allow-Credentials' header.
|
boolean |
isAllowingAllRequestedHeaders()
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 |
isSkippingResourceForCorsOptions()
If true, the filter does not call the server resource for OPTIONS method
of CORS request and set Access-Control-Allow-Methods header with
the default methods.
|
void |
setAllowedCredentials(boolean allowedCredentials)
If true, adds 'Access-Control-Allow-Credentials' header.
|
void |
setAllowedHeaders(java.util.Set<java.lang.String> allowedHeaders)
Sets the value of the 'Access-Control-Allow-Headers' response header.
|
void |
setAllowedOrigins(java.util.Set<java.lang.String> allowedOrigins)
Sets the value of 'Access-Control-Allow-Origin' header.
|
void |
setAllowingAllRequestedHeaders(boolean allowingAllRequestedHeaders)
If true, copies the value of 'Access-Control-Request-Headers' request
header into the 'Access-Control-Allow-Headers' response header.
|
void |
setDefaultAllowedMethods(java.util.Set<Method> defaultAllowedMethods)
Sets the list of methods allowed by default, used when
skippingResourceForCorsOptions is turned on. |
void |
setExposedHeaders(java.util.Set<java.lang.String> exposedHeaders)
Sets the value of 'Access-Control-Expose-Headers' response header.
|
void |
setMaxAge(int maxAge)
Sets the value of 'Access-Control-Max-Age' response header.
|
void |
setSkippingResourceForCorsOptions(boolean skipResourceForCorsOptions)
Sets the value of skipResourceForCorsOptions field.
|
createOutboundFilter, getContext, isEnabled, isStarted, isStopped, setContext, setEnabled, start, stop
public CorsService()
public CorsService(boolean enabled)
enabled
- True if the service has been enabled.public Filter createInboundFilter(Context context)
Service
createInboundFilter
in class Service
context
- The current context.public java.util.Set<java.lang.String> getAllowedHeaders()
public java.util.Set<java.lang.String> getAllowedOrigins()
public java.util.Set<Method> getDefaultAllowedMethods()
skippingResourceForCorsOptions
is turned on.skippingResourceForCorsOptions
is turned on.public java.util.Set<java.lang.String> getExposedHeaders()
public int getMaxAge()
public boolean isAllowedCredentials()
public boolean isAllowingAllRequestedHeaders()
allowedHeaders
.public boolean isSkippingResourceForCorsOptions()
public void setAllowedCredentials(boolean allowedCredentials)
allowedCredentials
- True to add the 'Access-Control-Allow-Credentials' header.public void setAllowedHeaders(java.util.Set<java.lang.String> allowedHeaders)
allowingAllRequestedHeaders
is false.allowedHeaders
- The value of 'Access-Control-Allow-Headers' response header.public void setAllowedOrigins(java.util.Set<java.lang.String> allowedOrigins)
allowedOrigins
- The value of 'Access-Control-Allow-Origin' header.public void setAllowingAllRequestedHeaders(boolean allowingAllRequestedHeaders)
allowedHeaders
.allowingAllRequestedHeaders
- 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 setDefaultAllowedMethods(java.util.Set<Method> defaultAllowedMethods)
skippingResourceForCorsOptions
is turned on.defaultAllowedMethods
- The list of methods allowed by default, used when skippingResourceForCorsOptions
is turned
on.public void setExposedHeaders(java.util.Set<java.lang.String> exposedHeaders)
exposedHeaders
- The value of 'Access-Control-Expose-Headers' response header.public void setMaxAge(int maxAge)
maxAge
- The value of 'Access-Control-Max-Age' response header.public void setSkippingResourceForCorsOptions(boolean skipResourceForCorsOptions)
skipResourceForCorsOptions
- True if the filter does not call the server resource for
OPTIONS method of CORS request.Copyright © 2005-2024 Restlet.