Pre-flight Check
A CORS aware client attempting to make a cross-origin request first issues a pre-flight check to the resource it is attempting to access.
This is an OPTIONS request containing an Origin header populated with the
location which is originating the request and an "Access-Control-Request-Method" header indicating
which method the real request uses. This request might optionally contain an
"Access-Control-Request-Headers" header indicating any headers which is also included in the
cross-origin request.
OPTIONS /resource HTTP/1.1
Origin: https://test.ibm.com
Access-Control-Request-Method: GET
Access-Control-Request-Headers: X-IBM-HEADER, X-IBM-HEADER-2A successful pre-flight request results in the web reverse proxy returning an empty response with HTTP status code 204. Additionally, the response contains headers which indicate to the client what is acceptable in is cross-origin requests.
204 NO CONTENT
Access-Control-Allow-Origin: https://test.ibm.com
Access-Control-Allow-Method: GET
Access-Control-Allow-Headers: X-IBM-HEADER, X-IBM-HEADER-2
Access-Control-Allow-Credentials: true
Access-Control-Max-Age: 3600Pre-flight Check Processing
[cors-policy:<policy-name>]
request-match
allow-origin
allow-credentials
handle-pre-flight
allow-header
allow-method
max-ageThe handle-pre-flight entry controls whether or not the web reverse proxy responds to pre-flight requests. See handle-pre-flight.
When set to false, pre-flight requests are forwarded to the back-end application like a normal request. When set to true, the web reverse proxy performs CORS processing and generates a pre-flight response without contacting the back-end application.
The processing described in Process Common to Pre-Flight Check and Regular Cross-Origin Requests takes place before the processing described that follows.
Evaluating Access-Control-Request-Method
The first step performed by the web reverse proxy when performing a pre-flight check is to evaluate if the method provided in the requests Access-Control-Request-Method header is permitted. The web reverse proxy indicates to clients which methods are permitted using the Access-Control-Request-Method header.
If no methods are configured, the web reverse proxy allows any method and returns the value provided by the client in the Access-Control-Request-Method header.
- Method names are compared in a case sensitive manner.
- Simple methods are only returned when the configured list of allowed methods for the policy is empty.
| Request Headers | Response from policy containing: allow-method = PUT allow-method = PATCH |
Response from policy containing: allow-method = |
|---|---|---|
|
|
|
|
CORS Error Response |
|
|
|
|
|
Forwarded to the back-end, not a pre-flight request | Forwarded to the back-end, not a pre-flight request |
|
CORS Error Response |
|
Evaluating Access-Control-Request-Headers
The list of headers indicated by the client is also checked to ensure they are valid according to the configured policy. The web reverse proxy indicates to clients which headers are acceptable using the Access-Control-Request-Headers header.
If no headers are configured, the web reverse proxy allows any headers and returns the value provided by the client in the Access-Control-Request-Headers header.
- Header names are compared in a case sensitive manner.
- Simple headers are only returned when the configured list of allowed methods for the policy is empty or if they are explicitly defined in the allow-header configuration entry.
| Request Headers | Response from policy containing: allow-header = X-IBM-HEADER allow-header = X-IBM-HEADER-2 |
Response from policy containing: allow-header = |
|---|---|---|
|
|
|
|
CORS Error Response |
|
|
|
|
|
|
|
Evaluating Access-Control-Max-Age
The web reverse proxy can indicate to the client how long (in seconds) they should cache the results of the pre-flight check using the Access-Control-Max-Age header.
If the maximum age entry (see max-age) is configured or invalid, no header is returned.
- -1: The response should not be cached at all
- 0: The client may cache this entry for any period of time it wishes
- >0: The client should cache this entry for no longer than the number of seconds given.
| Request Headers | Response from policy containing:allow-origin = https://test.ibm.com max-age = 600 |
Response from policy containing:allow-origin = https://test.ibm.com max-age = |
|---|---|---|
|
|
|