whatwg / fetch

Fetch Standard
https://fetch.spec.whatwg.org/
Other
2.12k stars 333 forks source link

How to send ‘OPTIONS * HTTP/1.1’ requests (asterisk form) with fetch()? #1622

Open geryogam opened 1 year ago

geryogam commented 1 year ago

From RFC 9110, HTTP Semantics:

An OPTIONS request with an asterisk ("*") as the request target (Section 7.1) applies to the server in general rather than to a specific resource. Since a server's communication options typically depend on the resource, the "*" request is only useful as a "ping" or "no-op" type of method; it does nothing beyond allowing the client to test the capabilities of the server. For example, this can be used to test a proxy for HTTP/1.1 conformance (or lack thereof).

I wrote an HTTP server in JavaScript running on Node and would like to write a unit test for checking how it responds to the following request:

OPTIONS * HTTP/1.1

How to send that request (asterisk form) with the fetch() JavaScript API?

I know that it is possible with Curl using the --request-target option (the question was asked on Stack Overflow):

curl --request-target '*' -X OPTIONS https://example.com/

If it’s not currently possible (like people seem to suggest on Stack Overflow), then interpret this issue as a feature request.