What is a CORS preflight request, and which requests trigger one?
Short answer
For 'non-simple' requests (custom headers, methods like PUT/DELETE, or a Content-Type other than a few basic ones), the browser automatically sends an OPTIONS request first, asking the server whether the actual request is allowed — only if the server responds affirmatively does…
Advertisement
AModel answer
For 'non-simple' requests (custom headers, methods like PUT/DELETE, or a Content-Type other than a few basic ones), the browser automatically sends an OPTIONS request first, asking the server whether the actual request is allowed — only if the server responds affirmatively does the browser send the real request.
Example
// Browser automatically sends, before your actual PUT request: // OPTIONS /api/users/1 // Access-Control-Request-Method: PUT // Access-Control-Request-Headers: content-type, authorization
Real-world example
Understanding why a simple GET request works cross-origin without extra config, but a PUT with a custom Authorization header triggers an extra network round-trip.
Likely follow-ups
- How can you configure a server to respond correctly to preflight OPTIONS requests?
Related topics