Please refer to the
CorsConfig
javadocs for information about all the
configuration options available.
Below are some of configuration discussed in this example:
Support only a specific origin
To support a single origin instead of the wildcard use the following:
CorsConfig corsConfig = CorsConfig.withOrigin("http://domain1.com")
Enable loading from the file system
To enable the server to handle an origin specified as 'null', which happens
when a web browser loads a file from the local file system use the following:
corsConfig.isNullOriginAllowed()
Enable request headers
To enable additional request headers:
corsConfig.allowedRequestHeaders("custom-request-header")
Expose response headers
By default a browser only exposes the following simple header:
- Cache-Control
- Content-Language
- Content-Type
- Expires
- Last-Modified
- Pragma
Any of the above response headers can be retrieved by:
xhr.getResponseHeader("Content-Type");
If you need to get access to other headers this must be enabled by the server, for example:
corsConfig.exposedHeaders("custom-response-header");