From f3a0c40f106e3eaf3d8b3f8a6c34664bb2722a6c Mon Sep 17 00:00:00 2001 From: Casey Bodley Date: Mon, 21 Nov 2016 11:18:42 -0500 Subject: [PATCH] rgw: only set CURLOPT_UPLOAD for PUT/POST requests when set on GET requests, curl sends a 'Transfer-encoding: chunked' header, but doesn't do the actual encoding to terminate the message Fixes: http://tracker.ceph.com/issues/17822 Signed-off-by: Casey Bodley --- src/rgw/rgw_http_client.cc | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/rgw/rgw_http_client.cc b/src/rgw/rgw_http_client.cc index 157644e38e8..076846c3082 100644 --- a/src/rgw/rgw_http_client.cc +++ b/src/rgw/rgw_http_client.cc @@ -226,6 +226,14 @@ static curl_slist *headers_to_slist(param_vec_t& headers) return h; } +static bool is_upload_request(const char *method) +{ + if (method == nullptr) { + return false; + } + return strcmp(method, "POST") == 0 || strcmp(method, "PUT") == 0; +} + /* * process a single simple one off request, not going through RGWHTTPManager. Not using * req_data. @@ -260,7 +268,9 @@ int RGWHTTPClient::process(const char *method, const char *url) } curl_easy_setopt(curl_handle, CURLOPT_READFUNCTION, simple_send_http_data); curl_easy_setopt(curl_handle, CURLOPT_READDATA, (void *)this); - curl_easy_setopt(curl_handle, CURLOPT_UPLOAD, 1L); + if (is_upload_request(method)) { + curl_easy_setopt(curl_handle, CURLOPT_UPLOAD, 1L); + } if (has_send_len) { curl_easy_setopt(curl_handle, CURLOPT_INFILESIZE, (void *)send_len); } @@ -336,7 +346,9 @@ int RGWHTTPClient::init_request(const char *method, const char *url, rgw_http_re } curl_easy_setopt(easy_handle, CURLOPT_READFUNCTION, send_http_data); curl_easy_setopt(easy_handle, CURLOPT_READDATA, (void *)req_data); - curl_easy_setopt(easy_handle, CURLOPT_UPLOAD, 1L); + if (is_upload_request(method)) { + curl_easy_setopt(easy_handle, CURLOPT_UPLOAD, 1L); + } if (has_send_len) { curl_easy_setopt(easy_handle, CURLOPT_INFILESIZE, (void *)send_len); } -- 2.47.3