Skip to content

Commit 54bc1be

Browse files
committed
net: CurlHttpClient: Call curl_easy_reset() to fix error 'rewinding of the data'
@okman334 reported an error when using the curl HTTP client after commit 775291f ("net: Allow curl handle in CurlHttpClient to be kept alive"): error: curl error: Send failed since rewinding of the data stream failed. Fix this by calling `curl_easy_reset()` before setting curl options. It reinitializes all options previously set on a specified curl handle to the default values while keeping the connection alive. Also, move the timeout options setting below the reset call to avoid losing the timeout options effect. Closes: #340 Reported-by: @okman334 Fixes: 775291f ("net: Allow curl handle in CurlHttpClient to be kept alive") Signed-off-by: Ammar Faizi <ammarfaizi2@gnuweeb.org>
1 parent 84e93a1 commit 54bc1be

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

src/net/CurlHttpClient.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,6 @@ static CURL* getCurlHandle(const CurlHttpClient *c_) {
2828
if (!curl) {
2929
throw std::runtime_error("curl_easy_init() failed");
3030
}
31-
curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, 20);
32-
curl_easy_setopt(curl, CURLOPT_TIMEOUT, c->_timeout);
3331
c->curlHandles[id] = curl;
3432
return curl;
3533
}
@@ -45,6 +43,9 @@ static std::size_t curlWriteString(char* ptr, std::size_t size, std::size_t nmem
4543
std::string CurlHttpClient::makeRequest(const Url& url, const std::vector<HttpReqArg>& args) const {
4644
CURL* curl = getCurlHandle(this);
4745

46+
curl_easy_reset(curl);
47+
curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, 20);
48+
curl_easy_setopt(curl, CURLOPT_TIMEOUT, _timeout);
4849
std::string u = url.protocol + "://" + url.host + url.path;
4950
if (args.empty()) {
5051
u += "?" + url.query;

0 commit comments

Comments
 (0)