]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
rgw: don't treat Content-Type as automatically dumpable metadata. 5969/head
authorRadoslaw Zarzynski <rzarzynski@mirantis.com>
Tue, 22 Sep 2015 15:27:33 +0000 (17:27 +0200)
committerRadoslaw Zarzynski <rzarzynski@mirantis.com>
Tue, 22 Sep 2015 15:33:49 +0000 (17:33 +0200)
Signed-off-by: Radoslaw Zarzynski <rzarzynski@mirantis.com>
src/rgw/rgw_rest.cc
src/rgw/rgw_rest_s3.cc
src/rgw/rgw_rest_swift.cc

index 8591bbe3ea3c4144745e0378a14b67ba3b8613cb..9e650ae51cf35ca57cbfc99f7d154e35d12a4fc9 100644 (file)
@@ -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<string, string> rgw_to_http_attrs;
@@ -168,12 +165,12 @@ static set<string> 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<string> extended_http_attrs;
index 570b00c0e9b106e23936fe706074ffa17e1d1a2c..c2bf671dc891ae1508ba71a9d6accf99aa3e222e 100644 (file)
@@ -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<string, string>::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());
       }
     }
   }
index 98d1accaaa018e939757b53605284367322c3536..5a846ecb30ccc357fea67b1358fa63be950e758f 100644 (file)
@@ -91,8 +91,7 @@ static void dump_account_metadata(struct req_state * const s,
     const char *name = iter->first.c_str();
     map<string, string>::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<string, string>::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<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. */
+    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;