CORS Preflight Request
For certain types of requests, the browser will send a "preflight" request using the OPTIONS method to check what's allowed before sending the actual request.
Browsers stop JavaScript on one website from reading responses from another, unless the other site
opts in with cross-origin resource sharing (CORS) headers.
For "simple" requests, such as a GET or a POST with form-style content, the browser sends the
request straight away and checks the CORS headers on the response. For anything else (a PUT or
DELETE, a JSON body, or a custom header like Authorization), the browser asks first:
OPTIONS /api/orders/42 HTTP/1.1
Origin: https://shop.example.com
Access-Control-Request-Method: DELETE
Access-Control-Request-Headers: authorizationThe server replies with the origins, methods and headers it accepts, and the browser sends the real request only if the answer covers it.
The preflight protects servers that were written before CORS existed, and never expected a browser
to send them a cross-origin DELETE request. Simple requests skip the preflight entirely, however,
and tools outside the browser ignore CORS altogether, so your server still needs authentication and
CSRF protection.