curl: add --follow

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
This commit is contained in:
Daniel Stenberg 2025-04-25 13:09:00 +02:00
parent 4d025fd912
commit 39543b7fdc
No known key found for this signature in database
GPG key ID: 5CC908FDB71E12C2
16 changed files with 340 additions and 10 deletions

View file

@ -101,6 +101,7 @@ DPAGES = \
fail-with-body.md \
fail.md \
false-start.md \
follow.md \
form-escape.md \
form-string.md \
form.md \

View file

@ -0,0 +1,25 @@
---
c: Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
SPDX-License-Identifier: curl
Long: follow
Help: Follow redirects per spec
Category: http
Added: 8.16.0
Multi: boolean
See-also:
- request
- location
Example:
- -X POST --follow $URL
---
# `--follow`
Instructs curl to follow HTTP redirects and to do the custom request method
set with --request when following redirects as the HTTP specification says.
The method string set with --request is used in subsequent requests for the
status codes 307 or 308, but may be reset to GET for 301, 302 and 303.
This is subtly different than --location, as that option always set the custom
method in all subsequent requests independent of response code.

View file

@ -9,6 +9,7 @@ Added: 7.10.4
Multi: boolean
See-also:
- user
- follow
Example:
- --location-trusted -u user:password $URL
- --location-trusted -H "Cookie: session=abc" $URL

View file

@ -11,6 +11,7 @@ Multi: boolean
See-also:
- resolve
- alt-svc
- follow
Example:
- -L $URL
---

View file

@ -199,6 +199,7 @@
--range (-r) 4.0
--rate 7.84.0
--raw 7.16.2
--follow 8.16.0
--referer (-e) 4.0
--remote-header-name (-J) 7.20.0
--remote-name (-O) 4.0