]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
rgw: convert header field underscores into dashes
authorYehuda Sadeh <yehuda@redhat.com>
Fri, 22 Aug 2014 22:12:16 +0000 (15:12 -0700)
committerYehuda Sadeh <yehuda@redhat.com>
Tue, 23 Sep 2014 20:55:48 +0000 (13:55 -0700)
Fixes: 9206
Backport: firefly

Certain web servers filter out underscores in the header field name.
Convert them into dashes.

Signed-off-by: Yehuda Sadeh <yehuda@redhat.com>
(cherry picked from commit 11acb7097ce21c6218dd48d0c21e0e04a361eb9a)

src/rgw/rgw_http_client.cc

index 1c6b6d4d71ba0e1929230ec23268b8be728dd0bb..3adc0aec6fc1a86fccbd931d9b5562edbd1f5fe4 100644 (file)
@@ -42,17 +42,8 @@ static size_t send_http_data(void *ptr, size_t size, size_t nmemb, void *_info)
   return ret;
 }
 
-int RGWHTTPClient::process(const char *method, const char *url)
+static curl_slist *headers_to_slist(list<pair<string, string> >& headers)
 {
-  int ret = 0;
-  CURL *curl_handle;
-
-  char error_buf[CURL_ERROR_SIZE];
-
-  curl_handle = curl_easy_init();
-
-  dout(20) << "sending request to " << url << dendl;
-
   curl_slist *h = NULL;
 
   list<pair<string, string> >::iterator iter;
@@ -63,11 +54,37 @@ int RGWHTTPClient::process(const char *method, const char *url)
     if (strncmp(val.c_str(), "HTTP_", 5) == 0) {
       val = val.substr(5);
     }
+
+    /* we need to convert all underscores into dashes as some web servers forbid them
+     * in the http header field names
+     */
+    for (size_t i = 0; i < val.size(); i++) {
+      if (val[i] == '_') {
+        val[i] = '-';
+      }
+    }
+
     val.append(": ");
     val.append(p.second);
     h = curl_slist_append(h, val.c_str());
   }
 
+  return h;
+}
+
+int RGWHTTPClient::process(const char *method, const char *url)
+{
+  int ret = 0;
+  CURL *curl_handle;
+
+  char error_buf[CURL_ERROR_SIZE];
+
+  curl_handle = curl_easy_init();
+
+  dout(20) << "sending request to " << url << dendl;
+
+  curl_slist *h = headers_to_slist(headers);
+
   curl_easy_setopt(curl_handle, CURLOPT_CUSTOMREQUEST, method);
   curl_easy_setopt(curl_handle, CURLOPT_URL, url);
   curl_easy_setopt(curl_handle, CURLOPT_NOPROGRESS, 1L);
@@ -139,20 +156,7 @@ int RGWHTTPClient::init_async(const char *method, const char *url, void **handle
 
   dout(20) << "sending request to " << url << dendl;
 
-  curl_slist *h = NULL;
-
-  list<pair<string, string> >::iterator iter;
-  for (iter = headers.begin(); iter != headers.end(); ++iter) {
-    pair<string, string>& p = *iter;
-    string val = p.first;
-
-    if (strncmp(val.c_str(), "HTTP_", 5) == 0) {
-      val = val.substr(5);
-    }
-    val.append(": ");
-    val.append(p.second);
-    h = curl_slist_append(h, val.c_str());
-  }
+  curl_slist *h = headers_to_slist(headers);
 
   req_data->h = h;