8

From RFC7230 Hypertext Transfer Protocol (HTTP/1.1): Message Syntax and Routing

When a client wishes to request OPTIONS for the server as a whole, as opposed to a specific named resource of that server, the client must send only "*" (%x2A) as the request-target.

To test how my site reacts I want to send the following request to the server.

OPTIONS * HTTP/1.1

I know I can use telnet, write my own client, etc. But I want to know if it's possible to do it with cURL?

Edit This can NOT be done with curl -X OPTIONS http://example.org, as suggested in a similar, but not identical, question That command will send OPTIONS http://example.org/ HTTP/1.1. I want to know if it's possible to send the asterisk with cURL.

Community
  • 1
  • 1
Adam B
  • 506
  • 1
  • 5
  • 13
  • 2
    Possible duplicate of [How to send a HTTP OPTIONS request from the command line?](http://stackoverflow.com/questions/14481850/how-to-send-a-http-options-request-from-the-command-line) – CodeCaster Apr 28 '16 at 20:47
  • Not a duplicate. That command will send "OPTIONS /" not "OPTIONS *". – Adam B Apr 29 '16 at 05:06
  • 1
    RFC 2616 is obsolete. You may want to cite https://greenbytes.de/tech/webdav/rfc7230.html#asterisk-form instead. (no, it doesn't change the nature of the question) – Julian Reschke Apr 29 '16 at 05:34

2 Answers2

10

Using -X OPTIONS only will send a slash and not an asterisk as path in the request.

In order to send a plain OPTIONS * to the server with curl, you need curl 7.55.0 or later and its --request-target option in addition to the -X flag. Used like this:

curl -X OPTIONS --request-target '*' https://example.com/
Daniel Stenberg
  • 54,736
  • 17
  • 146
  • 222
  • I have been trying to figure out how to do this for months. I even resorted to reading the curl code but abandoned that in preference for looking at Chrome extensions. I would be happy to fix it if you could point me to the right place. (nickshanks on github) – Nicholas Shanks Aug 25 '16 at 09:00
  • 1
    To me its not about where to "fix it", but rather "how" . No other HTTP method can do plain `*` like that so we need to figure out something new. I would recommend taking your ideas and discussions for that to the curl-library mailing list. – Daniel Stenberg Aug 25 '16 at 09:15
  • 1
    Regarding https://cool.haxx.se/mailman/listinfo/curl-library the subscribe form action is http not https – Nicholas Shanks Aug 25 '16 at 09:29
  • 1
    thanks for pointing that out, I think I've fixed the mailman subscription now to use HTTPS there as well! – Daniel Stenberg Aug 27 '16 at 15:47
-1

You can send custom requests with cURL by using the -x option, https://curl.haxx.se/docs/manpage.html#-x

So this command would look like this

curl -X OPTIONS http://example.com
sverasch
  • 102
  • 2