Browser security mechanism that allows servers to specify which origins can access their resources, bypassing the same-origin policy.
The Problem
Same-origin policy blocks cross-domain requests by default:
// ❌ Blocked without CORS// Page: https://myapp.comfetch('https://api.external.com/data')
How It Works
Browser sends request with Origin header
Server responds with CORS headers (or doesn’t)
Browser allows/blocks based on server response
For complex (non-simple) requests, browser sends preflight OPTIONS request first.
Complex/Non-Simple Requeset that triggers OPTIONS preflight
Complex/Non-Simple CORS Requeset that triggers OPTIONS preflight
Complex/Non-Simple CORS Requests & OPTIONS Preflight
What is a Non-Simple CORS Request?
A non-simple (or complex) CORS request is any cross-origin request that doesn’t meet the criteria for a “simple request”. These requests trigger an automatic OPTIONS preflight request from the browser before the actual request is sent.
Simple vs Non-Simple Requests
Simple CORS Requests (No Options Preflight)
Simple requests must meet ALL of the following criteria:
curl does NOT send preflight OPTIONS requests. It only sends the exact request you specify. To see the complete CORS preflight behavior, you must test from:
A web browser
Browser developer tools
Testing tools that simulate browser CORS behavior
curl is useful for testing the server’s response to individual requests, but won’t replicate the full browser CORS flow.