brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: curl --next sends two different requests in one command

Curl
~/tips/tip-curl-next-two-requests

curl https://example.com/ --next -d 'name=test' https://example.com/api/items

Splits one curl command into separate requests that each keep their own options.

Two different requests usually mean two curl commands joined with &&. curl can do both in one run.

--next (short form -:) starts a new, separate operation. Everything before it belongs to the first request and everything after it to the second. The manual’s own example does a GET and a POST in one go:

curl https://example.com/ --next -d 'name=test' https://example.com/api/items

That is useful for a quick check where the two requests have little in common, for example a HEAD request to one URL and a normal fetch of another:

curl -I https://example.com/ --next -sS -o out.json https://example.net/api/items

The rule to remember is that --next resets all local options. Only global options survive it. The manual names --verbose, --trace, --trace-ascii and --fail-early as global ones, and the entries for --parallel and --parallel-max say the same: you do not need to repeat them after --next.

So in the second example I had to write -sS again after --next, because it applied only to the first part otherwise. Headers, credentials, -o and -d all behave the same way: set them again where you need them. That is the caveat, and it tends to show up as a second request that misses its Authorization header.

It also pairs well with --parallel. With -Z in front, the separate operations run at the same time instead of one after the other. For anything with many options per request I would move to a config file with -K, which the manual lists as a related option.

Further reading: curl man page: –next

More Curl tips curl --trace-ascii – https://example.com/ Retry-After: 120 curl -fsS --fail-early \ url = "https://example.com/data/latest.json" curl -4 -s -o /dev/null -w '%{remote_ip} %{http_code}\n' https://example.com/ All Curl tips (71) All topics

Link