both std.net.curl and hunt http clients fail

drenoob dlang at none.org
Thu Jun 12 13:16:13 UTC 2025


Hello,

Finally re-discovering D again I wanted to try a small side 
project which largely is but an http[s] client. So, i tried first 
std.net.curl - and it failed. Then I tried the hunt lib - and it 
failed again.Note that in both cases I basically tried an example 
those libs provided.

Here's the curl code, in desperation slimmed down to an almost 
*verbatim copy* of their example:

     ------------ std.net.curl code --------------
      1|import std.net.curl, std.stdio;

      3|auto totLen = 0; // mine
      4|auto http = HTTP("https://some.url");
      5|http.onReceive = (ubyte[] data)
      6|{
      7|    /+ drop +/ totLen += data.length; // mine
      8|    return data.length;
      9|};
     10|http.onProgress = (size_t dltotal, size_t dlnow,
     11|                   size_t ultotal, size_t ulnow)
     12|{
     13|    writeln("Progress ", dltotal, ", ", dlnow, ", ", 
ultotal, ", ", ulnow);
     14|    return 0;
     15|};
     16|http.perform();
     // ---- End of code ---
the two lines I added or changed are commented '// mine''
the 'xx|' at the beginning of each line is the line number

This results in
  source/app.d(5,16): Error: variable name expected after type 
`http.onReceive`, not `=`
  http.onReceive = (ubyte[] data)
                    ^
  source/app.d(5,16): Error: declaration expected, not `=`
  http.onReceive = (ubyte[] data)
                    ^
  source/app.d(8,5): Error: `return` statement must be inside 
function scope
  return data.length;
  ^
  source/app.d(9,1): Error: unmatched closing brace
  };
  ^
  Error dmd failed with exit code 1.

======================= hunt lib ==============================
     import hunt.http;
     import std.stdio;

     enum tgtUrl = "https://some.url/";

     void main()
     {
         auto client = new HttpClient();
         auto request = new RequestBuilder().url(tgtUrl).build();
         auto response = client.newCall(request).execute();
         if (response !is null)
         {
             writeln("status code: %d", response.getStatus());
             writeln(response.getBody().asString());
         }
     }
     // ---- End of code ---
results in
../../.dub/packages/hunt-extra/1.2.3/hunt-extra/source/hunt/collection/Collections.d(157,19): Deprecation: a function template is not virtual so cannot be marked `override`
     override bool contains(E)(E o) {return o == element;}
                   ^
../../.dub/packages/hunt-extra/1.2.3/hunt-extra/source/hunt/math/BigInteger.d(1242,39): Deprecation: function `std.math.exponential.log` is deprecated - `std.math.exponential.log` called with argument types `(int)` matches both `log(real)`, `log(double)`, and `log(float)`. Cast argument to floating point type instead.
     logCache[i] = std.math.log(i);
                               ^
Building hunt-net 0.7.1: building configuration [default]
../../.dub/packages/hunt-extra/1.2.3/hunt-extra/source/hunt/collection/Collections.d(157,19): Deprecation: a function template is not virtual so cannot be marked `override`
     override bool contains(E)(E o) {return o == element;}
                   ^
Building hunt-http 0.8.2: building configuration [default]
../../.dub/packages/hunt-extra/1.2.3/hunt-extra/source/hunt/collection/Collections.d(157,19): Deprecation: a function template is not virtual so cannot be marked `override`
     override bool contains(E)(E o) {return o == element;}
                   ^
../../.dub/packages/hunt-http/0.8.2/hunt-http/source/hunt/http/server/HttpSession.d(528,41): Deprecation: slice of static array temporary returned by `toHexString(result)` assigned to longer lived variable `str`
     string str = toLower(toHexString(result));
                                     ^
Building app ~master: building configuration [application]
../../.dub/packages/hunt-extra/1.2.3/hunt-extra/source/hunt/collection/Collections.d(157,19): Deprecation: a function template is not virtual so cannot be marked `override`
     override bool contains(E)(E o) {return o == element;}
                   ^
====================================================================

Sorry, dear colleagues, while I still presume D be a *stable* and 
really decent language and very much welcome the fact that at 
least many libraries are not version 0.0.[whatever small number] 
(so basically alpha or beta at best), I hope you can understand 
that this first experience isn't exactly strengthening my hopes 
for and trust in the D universe ...

Or did I make a total noob mistake? If so (or even if not) please 
kindly let me know how to get some decent http client working.

Btw. DMD and dub have been freshly installed and should be 
current.

Thank you



More information about the Digitalmars-d mailing list