Skip to content

curl: add --follow #16543

Closed
bagder wants to merge 1 commit intomasterfrom
bagder/request-mode
Closed

curl: add --follow #16543
bagder wants to merge 1 commit intomasterfrom
bagder/request-mode

Conversation

@bagder
Copy link
Member

@bagder bagder commented Mar 3, 2025

Makes curl follow redirects an act on the response code and change a custom method accordingly, contrary to --location.

Potential future command line to send QUERY and following a redirect according to the status code:

curl -d "request-body" -X QUERY --follow https://example.com 

@bagder bagder added cmdline tool feature-window A merge of this requires an open feature window labels Mar 3, 2025
@bagder bagder marked this pull request as ready for review March 3, 2025 13:47
@testclutch

This comment was marked as resolved.

@bagder

This comment was marked as resolved.

@bagder bagder changed the title curl: add --request-mode all/obey/first curl: add --location-mode all/obey/first Mar 3, 2025
@bagder bagder force-pushed the bagder/request-mode branch from 57b9e36 to 4e5fe66 Compare March 6, 2025 16:03
@bagder bagder force-pushed the bagder/request-mode branch from 4e5fe66 to 0bac12b Compare March 15, 2025 20:55
@divinity76
Copy link
Contributor

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

@bagder
Copy link
Member Author

bagder commented Apr 25, 2025

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

I like that! 👍

@bagder bagder force-pushed the bagder/request-mode branch from 0bac12b to f422d01 Compare April 25, 2025 11:20
@bagder bagder changed the title curl: add --location-mode all/obey/first curl: add --location-mode keep/spec/init Apr 25, 2025
@github-actions github-actions bot added the tests label Apr 25, 2025
@dboehmer
Copy link

dboehmer commented Apr 25, 2025

I’m still thinking about the naming of the parameter and its modes 🫤

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 👍
  • 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

@icing
Copy link
Contributor

icing commented Apr 25, 2025

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

@bagder
Copy link
Member Author

bagder commented Apr 28, 2025

Naming is hard!

@bagder
Copy link
Member Author

bagder commented Apr 29, 2025

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 added a commit that referenced this pull request Jun 3, 2025
Sets the "mode" for how to treat and use a custom HTTP method when
following redirects.

add test 792 - 795

Assisted-by: Daniel Böhmer <post@daniel-boehmer.de>

Closes #16543
@bagder bagder force-pushed the bagder/request-mode branch from 953fa43 to 404abee Compare June 3, 2025 07:58
@bagder
Copy link
Member Author

bagder commented Jun 3, 2025

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.

@dfandrich
Copy link
Contributor

dfandrich commented Jun 3, 2025 via email

@bagder
Copy link
Member Author

bagder commented Jun 5, 2025

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 added a commit that referenced this pull request Jul 7, 2025
Sets the "mode" for how to treat and use a custom HTTP method when
following redirects.

add test 794 - 797

Assisted-by: Daniel Böhmer <post@daniel-boehmer.de>

Closes #16543
@bagder bagder force-pushed the bagder/request-mode branch from 404abee to 3964ec4 Compare July 7, 2025 10:47
bagder added a commit that referenced this pull request Jul 28, 2025
Sets the "mode" for how to treat and use a custom HTTP method when
following redirects.

add test 794 - 797

Assisted-by: Daniel Böhmer <post@daniel-boehmer.de>

Closes #16543
@bagder bagder force-pushed the bagder/request-mode branch from 3964ec4 to b19391f Compare July 28, 2025 21:19
@bagder bagder changed the title curl: add --location-mode keep/spec/init curl: add --redirect keep/spec/init Jul 28, 2025
@bagder
Copy link
Member Author

bagder commented Jul 28, 2025

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

@bagder
Copy link
Member Author

bagder commented Jul 28, 2025

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

@icing
Copy link
Contributor

icing commented Jul 29, 2025

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

bagder added a commit that referenced this pull request Jul 29, 2025
Sets the "mode" for how to treat and use a custom HTTP method when
following redirects.

add test 794 - 797

Assisted-by: Daniel Böhmer <post@daniel-boehmer.de>

Closes #16543
@bagder bagder force-pushed the bagder/request-mode branch from b19391f to a6817f9 Compare July 29, 2025 10:59
bagder added a commit that referenced this pull request Jul 29, 2025
Sets the "mode" for how to treat and use a custom HTTP method when
following redirects.

add test 794 - 797

Assisted-by: Daniel Böhmer <post@daniel-boehmer.de>

Closes #16543
@bagder bagder force-pushed the bagder/request-mode branch from a6817f9 to 8443972 Compare July 29, 2025 20:54
@bagder bagder changed the title curl: add --redirect keep/spec/init curl: add --redirect Jul 29, 2025
bagder added a commit that referenced this pull request Jul 30, 2025
Makes curl follow redirects an act on the response code and change a
custom method accordingly, contrary to --location.

Potential future command line to send QUERY and following a redirect
according to the status code:

    curl -d "request-body" -X QUERY --redirect https://example.com

add test 794,796,797

Assisted-by: Daniel Böhmer <post@daniel-boehmer.de>

Closes #16543
@bagder bagder force-pushed the bagder/request-mode branch from 8443972 to f2a641c Compare July 30, 2025 07:21
@bagder
Copy link
Member Author

bagder commented Jul 30, 2025

Any final words, comments, advice or objections?

@dboehmer
Copy link

dboehmer commented Jul 30, 2025

Your latest commit message f2a641c 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
Copy link

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

@bagder
Copy link
Member Author

bagder commented Jul 31, 2025

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

One more rename...

Makes curl follow redirects an act on the response code and change a
custom method accordingly, contrary to --location.

Potential future command line to send QUERY and following a redirect
according to the status code:

    curl -d "request-body" -X QUERY --follow https://example.com

add test 794,796,797

Assisted-by: Daniel Böhmer <post@daniel-boehmer.de>

Closes #16543
@bagder bagder force-pushed the bagder/request-mode branch from f2a641c to 39543b7 Compare July 31, 2025 07:22
@bagder bagder changed the title curl: add --redirect curl: add --follow Jul 31, 2025
@bagder bagder closed this in 13cbabf Aug 4, 2025
@bagder bagder deleted the bagder/request-mode branch August 4, 2025 15:13
@Krinkle
Copy link
Contributor

Krinkle commented Aug 5, 2025

For those looking, the handling of this new mode landed a few months earlier in libcurl at #16473

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cmdline tool feature-window A merge of this requires an open feature window tests

Development

Successfully merging this pull request may close these issues.

8 participants