curl: add --location-mode keep/spec/init
Sets the "mode" for how to treat and use a custom HTTP method when following redirects.
The idea being that a user can set location-mode: spec in their .curlrc or similar to get this functionality by default every time they use -L/--location.
Potential future command line to send QUERY and following a redirect according to the status code:
curl -d "request-body" -X QUERY --location-mode spec -L https://example.com
Analysis of PR #16543 at 07db6327:
Test 3001 failed, which has NOT been flaky recently, so there could be a real issue in this PR.
Generated by Testclutch
Maybe call it --method-mode since it is about the HTTP request method ?
--redirect-mode ?
--follow-mode ?
--location-mode ?
all, obey, first => keep, spec, initial?
all, obey, first => keep, spec, initial?
I like that! :+1:
I’m still thinking about the naming of the parameter and its modes :face_with_diagonal_mouth:
This not so much about handling the Location header with the next address but about which request method to use for requests following 30[12378] response codes. But I see that existing curl options are named --location-*.
Currently the man page will read:
--location-mode <mode>
and as mode is no preexisting technical term (like --create-file-mode is for Unix modes for permissions) I think it’s redundant and one could come up with a more descriptive name. I suggest --location-method <mode>.
My two cents on the mode names then:
spec—really great and unambiguous :+1:init—I have some trouble with that becausekeepis drafted to mean “use method from initial request” and they could be easy to be mixed up. Thinking about my comment appending the doc saying that subsequent requests will all be GET could this simply beget?keep—I think I also likedalla lot. I’d very much prefer to see a reference to “use method from initial request” butinitis currently chosen for “set only for initial request”—this doesn’t match to the parameter name, though, which focuses on the subsequent “location” requests
I read --location-mode more as --follow-X with values spec|same|reset.
Naming is hard!
To give us more time to think and discuss about the parameter naming, even on the option itself, we have decided to let this PR wait for the next feature window, presumably for 8.15.0 instead of 8.14.0.
Alternative names for the command line option to consider:
--follow [mode]
--redirect [mode]
We can also ponder making this new option also enable --location so that using this option alone is enough. Makes for shorter/easier command lines.
Enabling --location automatically has the disadvantage that this option can't be added to .curlrc as a default without also enabling location processing.
Enabling --location automatically has the disadvantage that this option can't be added to .curlrc as a default without also enabling location processing.
Right, but that can also be an advantage since that will force users to do it "right" and make old curl not work with it. Putting something in your .curlrc in your machine and having others run the same script without the new thing might lead to one invoke doing the right thing and another doing the wrong thing...
Now the option is --redirect [mode] and is a replacement for --location.
Now I'm thinking about removing the "mode" argument and just have --redirect do the "spec" mode...
Now I'm thinking about removing the "mode" argument and just have
--redirectdo the "spec" mode...
Makes sense to me.
(Can't miss the opportunity to bikeshed: --follow would also work for me😌)
Any final words, comments, advice or objections?
Your latest commit message f2a641c75a3747862be767e7a3fbfeaf3ca42141 seems to have two typos:
curl: add --redirEct
^ "e" missing
Makes curl follow redirects an act on the response code and change a custom method accordingly, contrary to --location.
^^ should this mean "and"?
Did you consider naming it --redirects (plural)? --redirect sounds like an imperative/command but it’s actually a mode of handling incoming redirect responses (possibly multiple of them).
A good point and a solid argument for @icing's proposal --follow.
One more rename...
For those looking, the handling of this new mode landed a few months earlier in libcurl at https://github.com/curl/curl/pull/16473