Skip to content

Commit

Permalink
fix type for content length parameter
Browse files Browse the repository at this point in the history
- curl expects a 64-bit curl_off_t type
- change method from size_t to ulong
- checked conversion using to!curl_off_t
- keep testing for magic size_t.max to not
  break code
  • Loading branch information
MartinNowak committed Aug 24, 2015
1 parent 4a496c8 commit 463d241
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions std/net/curl.d
Expand Up @@ -2990,9 +2990,9 @@ struct HTTP
/**
The content length in bytes when using request that has content
e.g. POST/PUT and not using chunked transfer. Is set as the
"Content-Length" header. Set to size_t.max to reset to chunked transfer.
"Content-Length" header. Set to ulong.max to reset to chunked transfer.
*/
@property void contentLength(size_t len)
@property void contentLength(ulong len)
{
CurlOption lenOpt;

Expand All @@ -3006,15 +3006,18 @@ struct HTTP
else
lenOpt = CurlOption.infilesize_large;

if (len == size_t.max)
if (size_t.max != ulong.max && len == size_t.max)
len = ulong.max; // check size_t.max for backwards compat, turn into error

if (len == ulong.max)
{
// HTTP 1.1 supports requests with no length header set.
addRequestHeader("Transfer-Encoding", "chunked");
addRequestHeader("Expect", "100-continue");
}
else
{
p.curl.set(lenOpt, len);
p.curl.set(lenOpt, to!curl_off_t(len));
}
}

Expand Down Expand Up @@ -3404,9 +3407,9 @@ struct FTP
/**
The content length in bytes of the ftp data.
*/
@property void contentLength(size_t len)
@property void contentLength(ulong len)
{
p.curl.set(CurlOption.infilesize_large, len);
p.curl.set(CurlOption.infilesize_large, to!curl_off_t(len));
}
}

Expand Down

0 comments on commit 463d241

Please sign in to comment.