[Issue 18318] std.net.curl.download silently ignores non-2xx http statuses
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Sun Jan 28 15:28:54 UTC 2018
https://issues.dlang.org/show_bug.cgi?id=18318
Aravinda <hallimanearavind at gmail.com> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |hallimanearavind at gmail.com
--- Comment #2 from Aravinda <hallimanearavind at gmail.com> ---
(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);
}
}
--
More information about the Digitalmars-d-bugs
mailing list