OPTIONS request method
Baseline
Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.
The OPTIONS HTTP method requests permitted communication options for a given URL or server.
This can be used to test the allowed HTTP methods for a request, or to determine whether a request would succeed when making a CORS preflighted request.
A client can specify a URL with this method, or an asterisk (*) to refer to the entire server.
| Request has body | May* |
|---|---|
| Successful response has body | May |
| Safe | Yes |
| Idempotent | Yes |
| Cacheable | No |
| Allowed in HTML forms | No |
* Although an OPTIONS message with a request body is technically allowed, it has no defined semantics.
You may include a body in an OPTIONS message as long as you provide a valid Content-Type header, and when you know the server expects it, as behavior is implementation-specific.
Syntax
OPTIONS *|<request-target>["?"<query>] HTTP/1.1
The request target may be either in 'asterisk form' * indicating the whole server, or a request target as is common with other methods:
*-
Indicates that the client wishes to request
OPTIONSfor the server as a whole, as opposed to a specific named resource of that server. <request-target>-
Identifies the target resource of the request when combined with the information provided in the
Hostheader. This is an absolute path (e.g.,/path/to/file.html) in requests to an origin server, and an absolute URL in requests to proxies (e.g.,http://www.example.com/path/to/file.html). <query>Optional-
An optional query component preceded by a question-mark
?. Often used to carry identifying information in the form ofkey=valuepairs.
Examples
>Identifying allowed request methods
To find out which request methods a server supports, one can use the curl command-line program to issue an OPTIONS request:
curl -X OPTIONS https://example.org -i
This creates the following HTTP request:
OPTIONS / HTTP/2
Host: example.org
User-Agent: curl/8.7.1
Accept: */*