Issue 12895 - std.net.curl doesn't allow to abort a request
Summary: std.net.curl doesn't allow to abort a request
Status: NEW
Alias: None
Product: D
Classification: Unclassified
Component: phobos (show other issues)
Version: D2
Hardware: All All
: P4 enhancement
Assignee: Jonas Drewsen
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-06-12 00:16 UTC by Martin Nowak
Modified: 2024-12-01 16:21 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Martin Nowak 2014-06-12 00:16:10 UTC
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@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
Comment 1 sigod 2015-10-19 21:16:49 UTC
> Note that this is already possible for Curl.perform but not with HTTP.perform, FTP.perform or SMTP.perform.

Shouldn't this be closed since all of mentioned `perform` functions accept `ThrowOnError` attribute?
Comment 2 Vladimir Panteleev 2017-07-02 02:42:46 UTC
(In reply to sigod from comment #1)
> Shouldn't this be closed since all of mentioned `perform` functions accept
> `ThrowOnError` attribute?

Martin, ping, is this still actionable?
Comment 3 dlangBugzillaToGithub 2024-12-01 16:21:26 UTC
THIS ISSUE HAS BEEN MOVED TO GITHUB

https://github.com/dlang/phobos/issues/10061

DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB