liveBook · Manning

Preflight request

As explained in Spring Security in Action, Second Edition

A preflight request is a browser-generated HTTP request that tests whether a cross-origin request is permitted before the browser sends the original request.

A preflight request is a browser-generated HTTP OPTIONS request that tests whether a cross-origin request is permitted before the browser sends the original request. The browser owns this decision; application code does not implement the preflight logic. section 10.1

A preflight flow proceeds as follows:

  • The browser sends an OPTIONS request when the cross-origin request requires preflight. section 10.1
  • The server responds with CORS headers describing allowed origins and methods. section 18.7
  • If the preflight fails, the browser does not honor the original request; if it succeeds, the browser sends it. section 10.1

Testing a preflight response

A MockMvc test can perform OPTIONS on /test with Origin and Access-Control-Request-Method: POST, then verify Access-Control-Allow-Origin, Access-Control-Allow-Methods, and a successful status. section 18.7

Figure 10.4 For simple requests, the browser sends the original request directly to the server. The browser rejects the response if the server doesn’t allow the origin. In some cases, the browser sends a preflight request to test whether the server accepts the origin. If the preflight request succeeds, the browser sends the original request.

Shows the contrast between direct simple requests and requests preceded by a preflight check. section 10.1

How Spring Security in Action, Second Edition covers it

How deep it goes
Describes browser responsibility, failure behavior, CORS headers, and MockMvc validation, without implementing browser-side preflight logic.
Examples
Uses a cross-origin POST example, browser console output, a request-flow figure, and a MockMvc OPTIONS test.
What it assumes
Assumes familiarity with cross-origin calls, HTTP methods, and response headers while teaching browser preflight behavior explicitly.
What you can do after
Diagnose/debug CORS behavior by inspecting OPTIONS requests and validating allowed-origin and allowed-method response headers.
How it connects
Connects preflight requests with CORS, HTTP OPTIONS, origins, Access-Control-Allow-Origin, and Access-Control-Allow-Methods.

Also explained in

Compare how 3 books explain preflight request →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Spring Security in Action, Second Edition. The section links point to the parts of the book it draws on.