curl 7.76.0, released on March 31, 2021, adds --fail-with-body for developers who need a failed HTTP request to leave behind the server’s explanation. The new command-line option preserves the response body while returning curl error 22 for HTTP response codes of 400 or higher. It is an alternative to --fail, not a new default: adopting it means changing the script’s options, not merely upgrading curl. [S6][S8]
The older --fail option already gives scripts an error signal, but suppresses the response body. curl’s documentation explains that an HTTP server may return an HTML document describing why it could not deliver the requested document. With --fail, that explanation is withheld from the output; with --fail-with-body, it can be kept. [S8][S9]
HTTP status and process exit status are different numbers. Under the new option’s documented rule, an HTTP 404 response is in the error range, while curl reports exit code 22. In a build log, 22 is not the server’s HTTP status. A developer who needs the server’s explanation can retain the body without dropping the nonzero exit signal that the surrounding job uses to detect failure. [S8]
The practical implication is to check curl’s result before treating a written file as the requested artifact. A server’s error document can now be present in the output even though the request failed. Keep that diagnostic output out of a successful-download path, and test the steps that read it before replacing --fail across shared scripts. [S8][S9]
The release’s documentation for the older --fail option warns that some unsuccessful responses can slip through, especially HTTP 401 and 407. The new option’s brief description establishes body retention; it should not be read as a promise to validate every authenticated exchange or the contents of an application response. Test an authenticated failure as well as a missing URL before relying on the revised job. [S8][S9]
Source documents
- curl 7.76.0 release changes — March 31, 2021https://curl.se/ch/7.76.0.html
- curl 7.76.0 command-line documentation: fail-with-bodyhttps://raw.githubusercontent.com/curl/curl/curl-7_76_0/docs/cmdline-opts/fail-with-body.d
- curl 7.76.0 command-line documentation: failhttps://raw.githubusercontent.com/curl/curl/curl-7_76_0/docs/cmdline-opts/fail.d
