When does the browser send an OPTIONS preflight and which headers does it check? See Access-Control-Request-Method/Headers matched against the server's Allow-* response.
Scenario presets
Request — the browser (page) side
Method
Content-Type
Custom header
Access-Control-Request-Headers: content-type, x-api-key
Response — headers the server sends
Access-Control-Allow-Origin
Access-Control-Allow-Methods
Access-Control-Allow-Headers
Headers the request needs + common values — click to toggle
Browser processing steps
Page issues a fetch request
Not a simple request — an OPTIONS preflight is required
OPTIONS preflight request sent
OPTIONS /data HTTP/1.1 Origin: https://myapp.example.com Access-Control-Request-Method: POST Access-Control-Request-Headers: content-type, x-api-key
Server's preflight response arrives
HTTP/1.1 204 No Content Access-Control-Allow-Origin: https://myapp.example.com Access-Control-Allow-Methods: GET, POST, PUT Access-Control-Allow-Headers: content-type, x-api-key
Allow-Origin matches the origin — pass
Request method is in Allow-Methods — pass
All request headers are in Allow-Headers — pass
No credentials — check skipped
Preflight passed — proceeding to the real request
Actual request sent
POST /data HTTP/1.1 Origin: https://myapp.example.com Content-Type: application/json X-Api-Key: s3cr3t
Server's actual response arrives
HTTP/1.1 200 OK
Access-Control-Allow-Origin: https://myapp.example.com
{"status": "ok"}Allow-Origin matches the origin — pass
Response delivered to JavaScript — success
Browser console
▸ The response was delivered to your JavaScript code.
Change any value and the steps below recompute instantly. Try the 'credentials + *' scenario to see why the wildcard fails.
When a request isn't 'simple', the browser first sends an OPTIONS preflight: Access-Control-Request-Method declares the intended method, Access-Control-Request-Headers the intended headers. It's a permission check before the real request.
The server answers with three headers: Access-Control-Allow-Origin, Allow-Methods, and Allow-Headers. If any doesn't cover the request, the browser never sends the real request at all.
Preflights add latency to every call — respond with Access-Control-Max-Age so the browser caches the result and skips repeated preflights. Essential for APIs using PUT/DELETE or Authorization headers. CORS Simulator