Bug 18318 – std.net.curl.download silently ignores non-2xx http statuses

Status
NEW
Severity
major
Priority
P2
Component
phobos
Product
D
Version
D2
Platform
All
OS
All
Creation time
2018-01-27T18:32:00Z
Last change time
2024-12-01T16:32:18Z
Keywords
pull
Assigned to
No Owner
Creator
Martin Nowak
Moved to GitHub: phobos#10300 →

Comments

Comment #0 by code — 2018-01-27T18:32:00Z
cat > bug.d << CODE import std.net.curl; void main() { // get("dlang.org/non-existent-foobar"); // throws HTTPStatusException 404 download("dlang.org/non-existent-foobar", "tmp"); // silently writes 404 response, with no way to detect the error } CODE dmd -run bug
Comment #1 by code — 2018-01-27T18:33:45Z
I does throw a CurlException for things like timeouts, connection-failures, or ssl issues.
Comment #2 by hallimanearavind — 2018-01-28T15:28:54Z
(In reply to Martin Nowak from comment #0) > cat > bug.d << CODE > import std.net.curl; > > void main() > { > // get("dlang.org/non-existent-foobar"); // throws HTTPStatusException > 404 > download("dlang.org/non-existent-foobar", "tmp"); // silently writes 404 > response, with no way to detect the error > } > CODE > > dmd -run bug Below code works with error handling. import std.stdio; import std.net.curl; void main() { auto url = "dlang.org/non-existent-foobar"; auto conn = HTTP(url); download(url, "tmp", conn); auto status = conn.statusLine(); if (status.code == 200){ writeln("Downloaded successfully!"); } else { writefln("Failed to download. Error: %d %s", status.code, status.reason); } }
Comment #3 by code — 2018-01-31T00:43:00Z
Comment #4 by code — 2018-01-31T00:48:07Z
(In reply to Aravinda from comment #2) > auto conn = HTTP(url); > download(url, "tmp", conn); > auto status = conn.statusLine(); > if (status.code == 200){ Thanks, that's a helpful workaround for the time being. But by default, high-level functions should throw on errors, so that they aren't accidentally ignored.
Comment #5 by dlang-bot — 2019-05-09T16:02:29Z
@MartinNowak updated dlang/phobos pull request #6102 "fix Issue 18318 - std.net.curl.download silently ignores non-2xx..." fixing this issue: - fix Issue 18318 - std.net.curl.download silently ignores non-2xx... ...http statuses - check status code of server response and throw HTTPStatusException - still downloads the page if intended - not using CURLOPT_FAILONERROR in the low-level API, as that has would be too disruptive, and comes with many catches itself i.e. only the high-level get/post/.../download/upload throw HTTPStatusExceptions https://github.com/dlang/phobos/pull/6102
Comment #6 by dlang-bot — 2019-11-18T22:08:31Z
@MoonlightSentinel created dlang/dmd pull request #10590 "build.d: Make download fail reliably" mentioning this issue: - build.d: Make download fail reliably `download` would sometimes return true on failure (caused by Issue 18318 which requires additional work in dub). This commit implements a temporary workaround and should be reverted when the issue is resolved. See https://issues.dlang.org/show_bug.cgi?id=18318 https://github.com/dlang/dmd/pull/10590
Comment #7 by dlang-bot — 2019-11-19T00:29:52Z
dlang/dmd pull request #10590 "build.d: Make download fail reliably" was merged into master: - 78e079b28027972b6cac862e81efd2f968b6f07c by MoonlightSentinel: build.d: Make download fail reliably `download` would sometimes return true on failure (caused by Issue 18318 which requires additional work in dub). This commit implements a temporary workaround and should be reverted when the issue is resolved. See https://issues.dlang.org/show_bug.cgi?id=18318 https://github.com/dlang/dmd/pull/10590
Comment #8 by robert.schadek — 2024-12-01T16:32:18Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/phobos/issues/10300 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB