Thread overview
[Issue 18318] std.net.curl.download silently ignores non-2xx http statuses
Jan 27, 2018
Martin Nowak
Jan 28, 2018
Aravinda
Jan 31, 2018
Martin Nowak
Jan 31, 2018
Martin Nowak
May 09, 2019
Dlang Bot
Nov 18, 2019
Dlang Bot
Nov 19, 2019
Dlang Bot
Dec 17, 2022
Iain Buclaw
January 27, 2018
https://issues.dlang.org/show_bug.cgi?id=18318

--- Comment #1 from Martin Nowak <code@dawg.eu> ---
I does throw a CurlException for things like timeouts, connection-failures, or ssl issues.

--
January 28, 2018
https://issues.dlang.org/show_bug.cgi?id=18318

Aravinda <hallimanearavind@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |hallimanearavind@gmail.com

--- Comment #2 from Aravinda <hallimanearavind@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);
    }
}

--
January 31, 2018
https://issues.dlang.org/show_bug.cgi?id=18318

Martin Nowak <code@dawg.eu> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |pull

--- Comment #3 from Martin Nowak <code@dawg.eu> ---
https://github.com/dlang/phobos/pull/6102

--
January 31, 2018
https://issues.dlang.org/show_bug.cgi?id=18318

--- Comment #4 from Martin Nowak <code@dawg.eu> ---
(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.

--
May 09, 2019
https://issues.dlang.org/show_bug.cgi?id=18318

--- Comment #5 from Dlang Bot <dlang-bot@dlang.rocks> ---
@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

--
November 18, 2019
https://issues.dlang.org/show_bug.cgi?id=18318

--- Comment #6 from Dlang Bot <dlang-bot@dlang.rocks> ---
@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

--
November 19, 2019
https://issues.dlang.org/show_bug.cgi?id=18318

--- Comment #7 from Dlang Bot <dlang-bot@dlang.rocks> ---
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

--
December 17, 2022
https://issues.dlang.org/show_bug.cgi?id=18318

Iain Buclaw <ibuclaw@gdcproject.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Priority|P5                          |P2

--