]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
rgw: refactor dumping metadata of Swift objects.
authorRadoslaw Zarzynski <rzarzynski@mirantis.com>
Fri, 13 Mar 2015 16:59:01 +0000 (17:59 +0100)
committerLoic Dachary <ldachary@redhat.com>
Wed, 6 May 2015 10:05:40 +0000 (12:05 +0200)
Backport: hammer
Signed-off-by: Radoslaw Zarzynski <rzarzynski@mirantis.com>
(cherry picked from commit ccf6eaac6f7068289c4a4ffd3f0481d497ba7c87)

src/rgw/rgw_rest_swift.cc

index c87163d71f64a8955fb3c1901dfe2e441a7eb12e..a2926a5d956aeb0e773614a142a3b242ae5df84c 100644 (file)
@@ -538,6 +538,41 @@ void RGWDeleteObj_ObjStore_SWIFT::send_response()
   rgw_flush_formatter_and_reset(s, s->formatter);
 }
 
+static void get_contype_from_attrs(map<string, bufferlist>& attrs,
+                                   string& content_type)
+{
+  map<string, bufferlist>::iterator iter = attrs.find(RGW_ATTR_CONTENT_TYPE);
+  if (iter != attrs.end()) {
+    content_type = iter->second.c_str();
+  }
+}
+
+static void dump_object_metadata(struct req_state * const s,
+                                 map<string, bufferlist> attrs)
+{
+  map<string, string> response_attrs;
+  map<string, string>::const_iterator riter;
+  map<string, bufferlist>::iterator iter;
+
+  for (iter = attrs.begin(); iter != attrs.end(); ++iter) {
+    const char *name = iter->first.c_str();
+    map<string, string>::const_iterator aiter = rgw_to_http_attrs.find(name);
+
+    if (aiter != rgw_to_http_attrs.end() &&
+        aiter->first.compare(RGW_ATTR_CONTENT_TYPE) != 0) {
+      /* Filter out Content-Type. It must be treated separately. */
+      response_attrs[aiter->second] = iter->second.c_str();
+    } else if (strncmp(name, RGW_ATTR_META_PREFIX, sizeof(RGW_ATTR_META_PREFIX)-1) == 0) {
+      name += sizeof(RGW_ATTR_META_PREFIX) - 1;
+      s->cio->print("X-Object-Meta-%s: %s\r\n", name, iter->second.c_str());
+    }
+  }
+
+  for (riter = response_attrs.begin(); riter != response_attrs.end(); ++riter) {
+    s->cio->print("%s: %s\r\n", riter->first.c_str(), riter->second.c_str());
+  }
+}
+
 int RGWCopyObj_ObjStore_SWIFT::init_dest_policy()
 {
   dest_policy.create_default(s->user.user_id, s->user.display_name);
@@ -619,9 +654,7 @@ void RGWCopyObj_ObjStore_SWIFT::send_response()
 
 int RGWGetObj_ObjStore_SWIFT::send_response_data(bufferlist& bl, off_t bl_ofs, off_t bl_len)
 {
-  const char *content_type = NULL;
-  map<string, string> response_attrs;
-  map<string, string>::iterator riter;
+  string content_type;
 
   if (sent_header)
     goto send_data;
@@ -643,34 +676,13 @@ int RGWGetObj_ObjStore_SWIFT::send_response_data(bufferlist& bl, off_t bl_ofs, o
       }
     }
 
-    for (iter = attrs.begin(); iter != attrs.end(); ++iter) {
-      const char *name = iter->first.c_str();
-      map<string, string>::iterator aiter = rgw_to_http_attrs.find(name);
-      if (aiter != rgw_to_http_attrs.end()) {
-        if (aiter->first.compare(RGW_ATTR_CONTENT_TYPE) == 0) { // special handling for content_type
-          content_type = iter->second.c_str();
-          continue;
-        }
-        response_attrs[aiter->second] = iter->second.c_str();
-      } else {
-        if (strncmp(name, RGW_ATTR_META_PREFIX, sizeof(RGW_ATTR_META_PREFIX)-1) == 0) {
-          name += sizeof(RGW_ATTR_META_PREFIX) - 1;
-          s->cio->print("X-Object-Meta-%s: %s\r\n", name, iter->second.c_str());
-        }
-      }
-    }
+    get_contype_from_attrs(attrs, content_type);
+    dump_object_metadata(s, attrs);
   }
 
   set_req_state_err(s, (partial_content && !ret) ? STATUS_PARTIAL_CONTENT : ret);
   dump_errno(s);
-
-  for (riter = response_attrs.begin(); riter != response_attrs.end(); ++riter) {
-    s->cio->print("%s: %s\r\n", riter->first.c_str(), riter->second.c_str());
-  }
-
-  if (!content_type)
-    content_type = "binary/octet-stream";
-  end_header(s, this, content_type);
+  end_header(s, this, !content_type.empty() ? content_type.c_str() : "binary/octet-stream");
 
   sent_header = true;