From: Radoslaw Zarzynski Date: Fri, 13 Mar 2015 16:59:01 +0000 (+0100) Subject: rgw: refactor dumping metadata of Swift objects. X-Git-Tag: v9.0.1~112^2~3 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=ccf6eaac6f7068289c4a4ffd3f0481d497ba7c87;p=ceph.git rgw: refactor dumping metadata of Swift objects. Backport: hammer Signed-off-by: Radoslaw Zarzynski --- diff --git a/src/rgw/rgw_rest_swift.cc b/src/rgw/rgw_rest_swift.cc index e10d0de6001d..cc9c39463b87 100644 --- a/src/rgw/rgw_rest_swift.cc +++ b/src/rgw/rgw_rest_swift.cc @@ -553,6 +553,41 @@ void RGWDeleteObj_ObjStore_SWIFT::send_response() rgw_flush_formatter_and_reset(s, s->formatter); } +static void get_contype_from_attrs(map& attrs, + string& content_type) +{ + map::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 attrs) +{ + map response_attrs; + map::const_iterator riter; + map::iterator iter; + + for (iter = attrs.begin(); iter != attrs.end(); ++iter) { + const char *name = iter->first.c_str(); + map::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); @@ -634,9 +669,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 response_attrs; - map::iterator riter; + string content_type; if (sent_header) goto send_data; @@ -658,34 +691,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::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;