What is a preflight request?
It is part of CORS. Before sending certain cross-origin requests from a script, the browser first sends an OPTIONS request that names the method and headers it wants to use. The server answers with the methods, headers and origins it allows. Only if the answer permits it does the browser send the real request.
Not every request is preflighted. A GET, HEAD or POST with only basic headers and a Content-Type of application/x-www-form-urlencoded, multipart/form-data or text/plain goes straight through. A preflight is triggered by other methods such as PUT or DELETE, by headers such as Authorization or a custom header, or by a Content-Type such as application/json.
For forms this means a fetch with a FormData body and an Accept header needs no preflight, while a fetch that sends JSON does. If the server does not answer the OPTIONS request correctly, the browser reports a CORS error and the submission is never sent.
OPTIONS /submit HTTP/1.1
Host: api.example.com
Origin: https://www.example.org
Access-Control-Request-Method: POST
Access-Control-Request-Headers: content-type
HTTP/1.1 204 No Content
Access-Control-Allow-Origin: https://www.example.org
Access-Control-Allow-Methods: POST
Access-Control-Allow-Headers: content-type