From: Radoslaw Zarzynski Date: Tue, 22 Sep 2015 15:27:33 +0000 (+0200) Subject: rgw: don't treat Content-Type as automatically dumpable metadata. X-Git-Tag: v10.0.1~126^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=88cffd87ca3f79020b9ae796fdf424222eda11d7;p=ceph.git rgw: don't treat Content-Type as automatically dumpable metadata. Signed-off-by: Radoslaw Zarzynski --- diff --git a/src/rgw/rgw_rest.cc b/src/rgw/rgw_rest.cc index 8591bbe3ea3c..9e650ae51cf3 100644 --- a/src/rgw/rgw_rest.cc +++ b/src/rgw/rgw_rest.cc @@ -32,15 +32,13 @@ struct rgw_http_attr { /* * mapping between rgw object attrs and output http fields */ -static struct rgw_http_attr rgw_to_http_attr_list[] = { - { RGW_ATTR_CONTENT_TYPE, "Content-Type"}, - { RGW_ATTR_CONTENT_LANG, "Content-Language"}, - { RGW_ATTR_EXPIRES, "Expires"}, - { RGW_ATTR_CACHE_CONTROL, "Cache-Control"}, - { RGW_ATTR_CONTENT_DISP, "Content-Disposition"}, - { RGW_ATTR_CONTENT_ENC, "Content-Encoding"}, - { RGW_ATTR_USER_MANIFEST, "X-Object-Manifest"}, - { NULL, NULL}, +static const struct rgw_http_attr base_rgw_to_http_attrs[] = { + { RGW_ATTR_CONTENT_LANG, "Content-Language" }, + { RGW_ATTR_EXPIRES, "Expires" }, + { RGW_ATTR_CACHE_CONTROL, "Cache-Control" }, + { RGW_ATTR_CONTENT_DISP, "Content-Disposition" }, + { RGW_ATTR_CONTENT_ENC, "Content-Encoding" }, + { RGW_ATTR_USER_MANIFEST, "X-Object-Manifest" }, }; @@ -52,14 +50,13 @@ struct generic_attr { /* * mapping between http env fields and rgw object attrs */ -struct generic_attr generic_attrs[] = { - { "CONTENT_TYPE", RGW_ATTR_CONTENT_TYPE }, - { "HTTP_CONTENT_LANGUAGE", RGW_ATTR_CONTENT_LANG }, - { "HTTP_EXPIRES", RGW_ATTR_EXPIRES }, - { "HTTP_CACHE_CONTROL", RGW_ATTR_CACHE_CONTROL }, +static const struct generic_attr generic_attrs[] = { + { "CONTENT_TYPE", RGW_ATTR_CONTENT_TYPE }, + { "HTTP_CONTENT_LANGUAGE", RGW_ATTR_CONTENT_LANG }, + { "HTTP_EXPIRES", RGW_ATTR_EXPIRES }, + { "HTTP_CACHE_CONTROL", RGW_ATTR_CACHE_CONTROL }, { "HTTP_CONTENT_DISPOSITION", RGW_ATTR_CONTENT_DISP }, - { "HTTP_CONTENT_ENCODING", RGW_ATTR_CONTENT_ENC }, - { NULL, NULL }, + { "HTTP_CONTENT_ENCODING", RGW_ATTR_CONTENT_ENC }, }; map rgw_to_http_attrs; @@ -168,12 +165,12 @@ static set hostnames_set; void rgw_rest_init(CephContext *cct, RGWRegion& region) { - for (struct rgw_http_attr *attr = rgw_to_http_attr_list; attr->rgw_attr; attr++) { - rgw_to_http_attrs[attr->rgw_attr] = attr->http_attr; + for (const auto& rgw2http : base_rgw_to_http_attrs) { + rgw_to_http_attrs[rgw2http.rgw_attr] = rgw2http.http_attr; } - for (struct generic_attr *gen_attr = generic_attrs; gen_attr->http_header; gen_attr++) { - generic_attrs_map[gen_attr->http_header] = gen_attr->rgw_attr; + for (const auto& http2rgw : generic_attrs) { + generic_attrs_map[http2rgw.http_header] = http2rgw.rgw_attr; } list extended_http_attrs; diff --git a/src/rgw/rgw_rest_s3.cc b/src/rgw/rgw_rest_s3.cc index 570b00c0e9b1..c2bf671dc891 100644 --- a/src/rgw/rgw_rest_s3.cc +++ b/src/rgw/rgw_rest_s3.cc @@ -138,22 +138,22 @@ int RGWGetObj_ObjStore_S3::send_response_data(bufferlist& bl, off_t bl_ofs, off_ 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 (response_attrs.count(aiter->second) > 0) // was already overridden by a response param - continue; - - if (aiter->first.compare(RGW_ATTR_CONTENT_TYPE) == 0) { // special handling for content_type - if (!content_type) - content_type = iter->second.c_str(); - continue; + if (response_attrs.count(aiter->second) == 0) { + /* Was not already overridden by a response param. */ + response_attrs[aiter->second] = iter->second.c_str(); } - 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_PREFIX) - 1; - s->cio->print("%s: %s\r\n", name, iter->second.c_str()); + } else if (iter->first.compare(RGW_ATTR_CONTENT_TYPE) == 0) { + /* Special handling for content_type. */ + if (!content_type) { + content_type = iter->second.c_str(); } + } else if (strncmp(name, RGW_ATTR_META_PREFIX, sizeof(RGW_ATTR_META_PREFIX)-1) == 0) { + /* User custom metadata. */ + name += sizeof(RGW_ATTR_PREFIX) - 1; + s->cio->print("%s: %s\r\n", name, iter->second.c_str()); } } } diff --git a/src/rgw/rgw_rest_swift.cc b/src/rgw/rgw_rest_swift.cc index 98d1accaaa01..5a846ecb30cc 100644 --- a/src/rgw/rgw_rest_swift.cc +++ b/src/rgw/rgw_rest_swift.cc @@ -91,8 +91,7 @@ static void dump_account_metadata(struct req_state * const s, const char *name = iter->first.c_str(); map::const_iterator geniter = rgw_to_http_attrs.find(name); - if (geniter != rgw_to_http_attrs.end() && - geniter->first.compare(RGW_ATTR_CONTENT_TYPE) != 0) { + if (geniter != rgw_to_http_attrs.end()) { s->cio->print("%s: %s\r\n", geniter->second.c_str(), iter->second.c_str()); } else if (strncmp(name, RGW_ATTR_META_PREFIX, PREFIX_LEN) == 0) { s->cio->print("X-Account-Meta-%s: %s\r\n", name + PREFIX_LEN, iter->second.c_str()); @@ -351,8 +350,7 @@ static void dump_container_metadata(struct req_state *s, RGWBucketEnt& bucket) const char *name = iter->first.c_str(); map::const_iterator geniter = rgw_to_http_attrs.find(name); - if (geniter != rgw_to_http_attrs.end() && - geniter->first.compare(RGW_ATTR_CONTENT_TYPE) != 0) { + if (geniter != rgw_to_http_attrs.end()) { s->cio->print("%s: %s\r\n", geniter->second.c_str(), iter->second.c_str()); } else if (strncmp(name, RGW_ATTR_META_PREFIX, PREFIX_LEN) == 0) { s->cio->print("X-Container-Meta-%s: %s\r\n", name + PREFIX_LEN, iter->second.c_str()); @@ -730,9 +728,7 @@ static void dump_object_metadata(struct req_state * const s, 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. */ + if (aiter != rgw_to_http_attrs.end()) { 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;