curl icon indicating copy to clipboard operation
curl copied to clipboard

curl: add --location-mode keep/spec/init

Open bagder opened this issue 9 months ago • 11 comments

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 

bagder avatar Mar 03 '25 12:03 bagder

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

testclutch avatar Mar 03 '25 14:03 testclutch

Maybe call it --method-mode since it is about the HTTP request method ?

--redirect-mode ?

--follow-mode ?

--location-mode ?

bagder avatar Mar 03 '25 15:03 bagder

all, obey, first => keep, spec, initial?

divinity76 avatar Apr 25 '25 07:04 divinity76

all, obey, first => keep, spec, initial?

I like that! :+1:

bagder avatar Apr 25 '25 07:04 bagder

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 because keep is 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 be get?
  • keep—I think I also liked all a lot. I’d very much prefer to see a reference to “use method from initial request” but init is currently chosen for “set only for initial request”—this doesn’t match to the parameter name, though, which focuses on the subsequent “location” requests

dboehmer avatar Apr 25 '25 13:04 dboehmer

I read --location-mode more as --follow-X with values spec|same|reset.

icing avatar Apr 25 '25 13:04 icing

Naming is hard!

bagder avatar Apr 28 '25 06:04 bagder

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.

bagder avatar Apr 29 '25 21:04 bagder

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.

bagder avatar Jun 03 '25 09:06 bagder

Enabling --location automatically has the disadvantage that this option can't be added to .curlrc as a default without also enabling location processing.

dfandrich avatar Jun 03 '25 15:06 dfandrich

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...

bagder avatar Jun 05 '25 10:06 bagder

Now the option is --redirect [mode] and is a replacement for --location.

bagder avatar Jul 28 '25 21:07 bagder

Now I'm thinking about removing the "mode" argument and just have --redirect do the "spec" mode...

bagder avatar Jul 28 '25 21:07 bagder

Now I'm thinking about removing the "mode" argument and just have --redirect do the "spec" mode...

Makes sense to me.

(Can't miss the opportunity to bikeshed: --follow would also work for me😌)

icing avatar Jul 29 '25 07:07 icing

Any final words, comments, advice or objections?

bagder avatar Jul 30 '25 12:07 bagder

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"?

dboehmer avatar Jul 30 '25 14:07 dboehmer

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).

dboehmer avatar Jul 30 '25 14:07 dboehmer

A good point and a solid argument for @icing's proposal --follow.

One more rename...

bagder avatar Jul 31 '25 07:07 bagder

For those looking, the handling of this new mode landed a few months earlier in libcurl at https://github.com/curl/curl/pull/16473

Krinkle avatar Aug 05 '25 01:08 Krinkle