blaster
blaster

Reputation: 8937

Suppress OPTIONS Requests in Angular CORS

If I have foreknowledge that CORS calls made with Angular will, indeed, work, can I suppress the OPTIONS calls so that they don't continue needlessly occurring in production?

Upvotes: 0

Views: 472

Answers (2)

SilverlightFox
SilverlightFox

Reputation: 33578

To avoid the OPTIONS request you need to make sure that your request is a "simple" request.

A simple cross-site request is one that:

  • Only uses GET, HEAD or POST. If POST is used to send data to the server, the Content-Type of the data sent to the server with the HTTP POST request is one of application/x-www-form-urlencoded, multipart/form-data, or text/plain.

  • Does not set custom headers with the HTTP Request (such as X-Modified, etc.)

Check that Angular isn't setting x-requested-with or anything else unexpected.

Upvotes: 0

Ali Habibzadeh
Ali Habibzadeh

Reputation: 11568

This OPTIONS request tells the client if a CORS request will be allowed; and, for those requests, which methods (GET, POST, PUT, etc.) can be executed.

According to W3c options call is not required if you are implementing only simple methods: GET/POST/HEAD.

So where you set your Access-Control-Allow-Methods if it is * try changing it to "GET,POST" and based on the standard (if the browser follows), your browser doesn't need to fire the options call.

Upvotes: 1

Related Questions