]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
rgw: Swift API. The second way of specifying desirable response format.
authorDmytro Iurchenko <diurchenko@mirantis.com>
Mon, 9 Feb 2015 15:07:53 +0000 (17:07 +0200)
committerYehuda Sadeh <yehuda@redhat.com>
Tue, 10 Feb 2015 22:07:40 +0000 (14:07 -0800)
OpenStack Object Storage API v1 defines two ways for the client to tell which response format it understands.
Until now RGW looked at query variable 'format' only. This commit implements the second way of setting the format by
providing 'Accept' HTTP-header with the desirable response mime-type.

Backport: hammer
Fixes: #10746
Reviewed-by: Yehuda Sadeh <yehuda@redhat.com>
Signed-off-by: Dmytro Iurchenko <diurchenko@mirantis.com>
src/rgw/rgw_rest.cc

index b7c07d4e515ede72a709aa2dd54c248246f3ec82..93f5b3f0b26c480e3e97e9e9fc79cfc00196c2ae 100644 (file)
@@ -1086,6 +1086,21 @@ int RGWHandler_ObjStore::allocate_formatter(struct req_state *s, int default_typ
       s->format = RGW_FORMAT_XML;
     } else if (format_str.compare("json") == 0) {
       s->format = RGW_FORMAT_JSON;
+    } else {
+      const char *accept = s->info.env->get("HTTP_ACCEPT");
+      if (accept) {
+        char format_buf[64];
+        unsigned int i = 0;
+        for (; i < sizeof(format_buf) - 1 && accept[i] && accept[i] != ';'; ++i) {
+          format_buf[i] = accept[i];
+        }
+        format_buf[i] = 0;
+        if ((strcmp(format_buf, "text/xml") == 0) || (strcmp(format_buf, "application/xml") == 0)) {
+          s->format = RGW_FORMAT_XML;
+        } else if (strcmp(format_buf, "application/json") == 0) {
+          s->format = RGW_FORMAT_JSON;
+        }
+      }
     }
   }