CORS Preflight Requests Explained with Real OPTIONS Examples

A CORS preflight is the browser asking a server for permission before it sends certain cross-origin requests. It is not an error by itself and it is not a request your JavaScript normally creates manually.

Walk through a preflight from request to response

Assume a browser page at https://app.example wants to send JSON with an authorization header to https://api.example/orders. Because this is not a CORS-safelisted request, the browser can send a preflight before the application request.

OPTIONS /orders HTTP/1.1
Origin: https://app.example
Access-Control-Request-Method: POST
Access-Control-Request-Headers: authorization, content-type

A narrowly configured API might answer:

HTTP/1.1 204 No Content
Access-Control-Allow-Origin: https://app.example
Access-Control-Allow-Methods: POST
Access-Control-Allow-Headers: Authorization, Content-Type
Vary: Origin
Access-Control-Max-Age: 600

If the browser accepts that preflight, it can proceed with the POST. The actual POST response must still carry the appropriate Access-Control-Allow-Origin header; passing the preflight does not automatically make the final response readable.

Why “it works in curl” is not a CORS test

cURL is not a web browser and does not enforce the browser same-origin policy. A terminal request can return 200 while browser JavaScript is blocked from reading the same response. When debugging CORS, inspect the browser Network panel and distinguish the OPTIONS request from the application request.

Common preflight failures

SymptomLikely causeCheck
OPTIONS returns 404/405Router/proxy does not handle OPTIONSWeb server, reverse proxy and framework routes
Requested header rejectedHeader missing from allow-listAccess-Control-Allow-Headers
Method rejectedMethod not permittedAccess-Control-Allow-Methods
Correct origin sometimes receives wrong cached responseCache not varying by OriginVary: Origin and CDN behavior
Preflight passes but JS still failsFinal response lacks CORS header or credentials mismatchInspect the POST/GET response too

Do not turn debugging into a permanent wildcard

A frequent emergency fix is to reflect every incoming Origin or allow broad methods/headers. That can hide the immediate error while widening who may call the API from browser contexts. Prefer an explicit allow-list that matches the environments you operate, and keep development origins separate from production policy.

What to capture in a bug report

Record the page origin, target URL, requested method, requested headers, preflight status, preflight response headers and final response headers. That evidence is much more useful than a screenshot of a generic browser CORS error. The HTTP Header Parser can help format captured headers, while the CORS Header Generator is a starting point for configuration—not a replacement for testing the deployed response.

References

About the review

This guide is maintained by William. Technical claims are checked against primary or authoritative references where applicable. See How We Test CodeNimbleTools for the site-wide review and correction process.