Skip to content

Commit

Permalink
rgw: refactor dumping metadata of Swift objects.
Browse files Browse the repository at this point in the history
Backport: hammer
Signed-off-by: Radoslaw Zarzynski <rzarzynski@mirantis.com>
(cherry picked from commit ccf6eaa)
  • Loading branch information
rzarzynski authored and ldachary committed May 6, 2015
1 parent b034511 commit e749701
Showing 1 changed file with 39 additions and 27 deletions.
66 changes: 39 additions & 27 deletions src/rgw/rgw_rest_swift.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand All @@ -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;

Expand Down

0 comments on commit e749701

Please sign in to comment.