[Issue 12895] New: std.net.curl doesn't allow to abort a request

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Wed Jun 11 17:16:10 PDT 2014


https://issues.dlang.org/show_bug.cgi?id=12895

          Issue ID: 12895
           Summary: std.net.curl doesn't allow to abort a request
           Product: D
           Version: D2
          Hardware: x86_64
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P1
         Component: Phobos
          Assignee: nobody at puremagic.com
          Reporter: code at dawg.eu

The official libcurl solution to abort a running HTTP request is to return a
non-zero value from the onProgress callback
(http://curl.haxx.se/libcurl/c/curl_easy_setopt.html#CURLOPTPROGRESSFUNCTION).
The problem is that std.net.curl will throw an unspecific CurlException, so the
API offers no way to handle that error.

----
import std.net.curl;

void main()
{
    auto http = HTTP("www.example.com");
    http.onProgress = (dltot, dlnow, ultot, ulnow)
    {
        if (dlnow > 1024)
            return 1;
        return 0;
    };
    http.perform();
}
----
std.net.curl.CurlException at std/net/curl.d(3592): Operation was aborted by an
application callback on handle 1C94B00
----

I think allowing to pass a boolean to perform() so it returns the error code
instead of throwing an error would be a good solution. Note that this is
already possible for Curl.perform but not with HTTP.perform, FTP.perform or
SMTP.perform.

http://dlang.org/phobos/std_net_curl.html#.Curl.perform
http://dlang.org/phobos/std_net_curl.html#.HTTP.perform
http://dlang.org/phobos/std_net_curl.html#.FTP.perform
http://dlang.org/phobos/std_net_curl.html#.SMTP.perform

--


More information about the Digitalmars-d-bugs mailing list