Skip to content

Commit

Permalink
don't send Transfer-Encoding: chunked for newer libcurl
Browse files Browse the repository at this point in the history
  • Loading branch information
orignal committed Sep 18, 2022
1 parent 7e51386 commit 1e531be
Showing 1 changed file with 6 additions and 24 deletions.
30 changes: 6 additions & 24 deletions util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -272,23 +272,6 @@ static size_t all_data_cb(const void *ptr, size_t size, size_t nmemb,
return len;
}

static size_t upload_data_cb(void *ptr, size_t size, size_t nmemb,
void *user_data)
{
struct upload_buffer *ub = (struct upload_buffer *)user_data;
unsigned int len = (unsigned int)(size * nmemb);

if (len > ub->len - ub->pos)
len = (unsigned int)(ub->len - ub->pos);

if (len) {
memcpy(ptr, (char*)ub->buf + ub->pos, len);
ub->pos += len;
}

return len;
}

#if LIBCURL_VERSION_NUM >= 0x071200
static int seek_data_cb(void *user_data, curl_off_t offset, int origin)
{
Expand Down Expand Up @@ -429,7 +412,6 @@ static json_t *json_rpc_call(CURL *curl, const char *url,
json_t *val, *err_val, *res_val;
int rc;
struct data_buffer all_data = { 0 };
struct upload_buffer upload_data;
json_error_t err;
struct curl_slist *headers = NULL;
char *httpdata;
Expand All @@ -455,10 +437,12 @@ static json_t *json_rpc_call(CURL *curl, const char *url,
curl_easy_setopt(curl, CURLOPT_TCP_NODELAY, 1);
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, all_data_cb);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &all_data);
curl_easy_setopt(curl, CURLOPT_READFUNCTION, upload_data_cb);
curl_easy_setopt(curl, CURLOPT_READDATA, &upload_data);
#if LIBCURL_VERSION_NUM >= 0x071200
curl_easy_setopt(curl, CURLOPT_SEEKFUNCTION, &seek_data_cb);
struct upload_buffer upload_data;
upload_data.buf = rpc_req;
upload_data.len = strlen(rpc_req);
upload_data.pos = 0;
curl_easy_setopt(curl, CURLOPT_SEEKDATA, &upload_data);
#endif
curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, curl_err_str);
Expand All @@ -479,14 +463,12 @@ static json_t *json_rpc_call(CURL *curl, const char *url,
curl_easy_setopt(curl, CURLOPT_SOCKOPTFUNCTION, sockopt_keepalive_cb);
#endif
curl_easy_setopt(curl, CURLOPT_POST, 1);
curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, strlen (rpc_req));
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, rpc_req);

if (opt_protocol)
applog(LOG_DEBUG, "JSON protocol request:\n%s", rpc_req);

upload_data.buf = rpc_req;
upload_data.len = strlen(rpc_req);
upload_data.pos = 0;
sprintf(len_hdr, "Content-Length: %lu", (unsigned long) upload_data.len);
sprintf(hashrate_hdr, "X-Mining-Hashrate: %llu", (unsigned long long) global_hashrate);

headers = curl_slist_append(headers, "Content-Type: application/json");
Expand Down

0 comments on commit 1e531be

Please sign in to comment.