Skip to content

Commit

Permalink
std.net.curl: Implement seeking in basic HTTP requests
Browse files Browse the repository at this point in the history
This enables reposting the data after a redirect, for example.
  • Loading branch information
CyberShadow committed Oct 10, 2012
1 parent 8131a49 commit 6625029
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions std/net/curl.d
Expand Up @@ -710,14 +710,28 @@ private auto _basicHTTP(T)(const(char)[] url, const(void)[] sendData, HTTP clien
(client.method == HTTP.Method.post || client.method == HTTP.Method.put))
{
client.contentLength = sendData.length;
auto remainingData = sendData;
client.onSend = delegate size_t(void[] buf)
{
size_t minLen = min(buf.length, sendData.length);
size_t minLen = min(buf.length, remainingData.length);
if (minLen == 0) return 0;
buf[0..minLen] = sendData[0..minLen];
sendData = sendData[minLen..$];
buf[0..minLen] = remainingData[0..minLen];
remainingData = remainingData[minLen..$];
return minLen;
};
client.handle.onSeek = delegate(long offset, CurlSeekPos mode)
{
switch (mode)
{
case CurlSeekPos.set:
remainingData = sendData[cast(size_t)offset..$];
return CurlSeek.ok;
default:
// As of curl 7.18.0, libcurl will not pass
// anything other than CurlSeekPos.set.
return CurlSeek.cantseek;
}
};
}

client.onReceiveHeader = (in char[] key,
Expand Down

0 comments on commit 6625029

Please sign in to comment.