Skip to content

http: add CURLOPT_FAILON_STATUS and --fail-on-status - #20114

Closed
tiymat wants to merge 2 commits into
curl:masterfrom
tiymat:fail-status
Closed

tiymat wants to merge 2 commits into
curl:masterfrom
tiymat:fail-status

Conversation

@tiymat

@tiymat tiymat commented Dec 30, 2025

Copy link
Copy Markdown
Contributor

I took a swing at https://github.com/curl/curl/blob/master/docs/TODO.md#specify-which-response-codes-that-make--f--fail-return-error by adding a new option that accepts statuses and ranges of statuses to fail on, like 404,500-599.

One implementation detail I'm wondering about is when e.g. --fail-on-status 204 is specified, should curl fail ONLY on status 204, or on status 204 IN ADDITION TO the other status codes that http_should_fail considers failures? The current state of my implementation is that it would only fail on 204 in that case.

@testclutch

Copy link
Copy Markdown

Analysis of PR #20114 at 49ede89a:

Test ../../tests/http/test_03_goaway.py::TestGoAway::test_03_02_h3_goaway failed, but it has been 0.7% flaky lately, so it's probably NOT a fault of the PR. Note that this test has failed in 2 different CI jobs (the link just goes to one of them).

Test 100 failed, which has NOT been flaky recently, so there could be a real issue in this PR. Note that this test has failed in 4 different CI jobs (the link just goes to one of them).

Test 101 failed, which has NOT been flaky recently, so there could be a real issue in this PR. Note that this test has failed in 4 different CI jobs (the link just goes to one of them).

Test 102 failed, which has NOT been flaky recently, so there could be a real issue in this PR. Note that this test has failed in 4 different CI jobs (the link just goes to one of them).

Test 103 failed, which has NOT been flaky recently, so there could be a real issue in this PR. Note that this test has failed in 4 different CI jobs (the link just goes to one of them).

Test 104 failed, which has NOT been flaky recently, so there could be a real issue in this PR. Note that this test has failed in 4 different CI jobs (the link just goes to one of them).

Test 105 failed, which has NOT been flaky recently, so there could be a real issue in this PR. Note that this test has failed in 2 different CI jobs (the link just goes to one of them).

There are more failures, but that's enough from Gha.

Generated by Testclutch

@bagder

bagder commented Dec 31, 2025

Copy link
Copy Markdown
Member
  1. The TODO files speaks of a curl command line option. I'm not convinced libcurl needs this option.
  2. I can imagine a common use case would be "treat everything except 200 an error". Should there be something for that?

should curl fail ONLY on status 204, or on status 204 IN ADDITION TO the other status codes

I think it needs to replace the other ones, otherwise you need a syntax to remove the default ones as well.

@tiymat

tiymat commented Jan 6, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for your comments!

The TODO files speaks of a curl command line option. I'm not convinced libcurl needs this option.

Just to make sure I understand, would the alternative be using the CURLOPT_HEADERFUNCTION callback to check the status against the user-provided values, and if it's a fail, return CURL_WRITEFUNC_ERROR?

I can imagine a common use case would be "treat everything except 200 an error". Should there be something for that?

Hmm, I take it --fail-on-status 0-199,201-999 would be too verbose? Maybe the user could use some kind of operator like ! or * or something for the specific case of "anything but this is an error"? Like --fail-on-status !200?

@tiymat

tiymat commented May 9, 2026

Copy link
Copy Markdown
Contributor Author

Closing this as I couldn't find a way to make the new approach work.

@tiymat tiymat closed this May 9, 2026
@tiymat
tiymat deleted the fail-status branch May 26, 2026 22:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Development

Successfully merging this pull request may close these issues.

3 participants