]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
rgw: accept data only at the first time in response to a request 8084/head
authorsunspot <sunspot0105@gmail.com>
Mon, 14 Mar 2016 08:03:14 +0000 (16:03 +0800)
committersunspot <sunspot0105@gmail.com>
Tue, 15 Mar 2016 09:55:12 +0000 (17:55 +0800)
Because the member "max_response" in class "RGWRESTSimpleRequest" is
initialized 0, data packages cannot be accepted when the function
"receive_data()" is called again.

This patch initialize the value of "max_response" to "content-length".

Signed-off-by: sunspot <sunspot0105@gmail.com>
src/rgw/rgw_rest_client.cc
src/rgw/rgw_rest_client.h

index 5a1bf9be45d5c1ad144125fc5b112d656fa00d0b..fc874f0d6f2fa932b9e502f75ed04bba4cbf5ac4 100644 (file)
@@ -22,6 +22,22 @@ int RGWRESTSimpleRequest::get_status()
   return status;
 }
 
+int RGWRESTSimpleRequest::handle_header(const string& name, const string& val) 
+{
+  if (name == "CONTENT_LENGTH") {
+    string err;
+    long len = strict_strtol(val.c_str(), 10, &err);
+    if (!err.empty()) {
+      ldout(cct, 0) << "ERROR: failed converting content length (" << val << ") to int " << dendl;
+      return -EINVAL;
+    }
+
+    max_response = len;
+  }
+
+  return 0;
+}
+
 int RGWRESTSimpleRequest::receive_header(void *ptr, size_t len)
 {
   char line[len + 1];
@@ -143,10 +159,14 @@ int RGWRESTSimpleRequest::send_data(void *ptr, size_t len)
 
 int RGWRESTSimpleRequest::receive_data(void *ptr, size_t len)
 {
-  if (response.length() > max_response)
+  size_t cp_len, left_len;
+
+  left_len = max_response > response.length() ? (max_response - response.length()) : 0;
+  if (left_len == 0)
     return 0; /* don't read extra data */
 
-  bufferptr p((char *)ptr, len);
+  cp_len = (len > left_len) ? left_len : len;
+  bufferptr p((char *)ptr, cp_len);
 
   response.append(p);
 
index fb308f2a104f865624ac96f7204cdae19ce0f6cb..eb6e7aa2700d63096bd2b83e2c92ec3dd46cc9e2 100644 (file)
@@ -25,7 +25,7 @@ protected:
   size_t max_response; /* we need this as we don't stream out response */
   bufferlist response;
 
-  virtual int handle_header(const string& name, const string& val) { return 0; }
+  virtual int handle_header(const string& name, const string& val);
   void append_param(string& dest, const string& name, const string& val);
   void get_params_str(map<string, string>& extra_args, string& dest);