CS FundamentalsVery hardProduct-company web interview

A web app at https://app.example.com sends a PUT request with a JSON body to https://api.example.com. Before the PUT, the browser sends another request. What is it, and why?

  1. A. An OPTIONS preflight request, because a cross-origin PUT with a JSON content type is not a 'simple' request, so the browser asks the server which methods and headers it allows
  2. B. A HEAD request to check the file size
  3. C. A GET request to fetch a CSRF token automatically
  4. D. No extra request is sent; CORS applies only to GET

Correct answer: A. An OPTIONS preflight request, because a cross-origin PUT with a JSON content type is not a 'simple' request, so the browser asks the server which methods and headers it allows

Different subdomains are different origins. For non-simple methods or headers the browser sends a CORS preflight (OPTIONS) and proceeds only if the response's Access-Control-Allow-* headers permit it.

More Software Engineering, Git and Cloud Basics questions

Exams that ask this topic