In the early days of curl development we (I suppose it was me personally but let’s stick with we so that I can pretend the blame is not all on me) made the possibly slightly unwise decision to make the -X option change the HTTP method for all requests in a curl transfer, even when -L is used – and independently of what HTTP responses the server returns.
That decision made me write blog posts and inform people all over about how using -X superfluously causes problems.
In curl 8.16.0, we introduce a different take on the problem, or better yet, a solution really: a new command line option that offers a modified behavior. Possibly the behavior people were thinking curl was having all along.
Just learn to use --follow
going forward (in curl 8.16.0 and later).
This option works fine together with -X and will adjust the method in the possible subsequent requests according to the HTTP response code.
A long time ago I wrote separately about the different HTTP response codes and what they mean in terms of changing (or not) the method.
–location remains the same
Since we cannot break existing users and scripts, we had to leave the exiting --location
option working exactly like it always has. This option is this mutually exclusive with --follow
, so only pick one.
QUERY friendly
Part of the reason for this new option is to make sure curl can follow redirects correctly for other HTTP methods than the good old fashioned GET, POST and PUT. We already see PATCH used to some extent but perhaps more important is the work on the spec for the new QUERY method. It is a flavor of POST, but with a few minor but important different properties. Possibly enough for me to write a separate blog post about, but right now we can stick to it being “like POST”, in particular from a HTTP client’s perspective.
We want curl to be able to do a “post” but with a QUERY method and still follow redirects correctly. The -L and -X combination does not support this.
curl can be made to issue a proper QUERY request and follow redirects correctly like this:
curl -X QUERY --follow -d sendthis https://example.com/
Thank you for flying curl!