From: Dmytro Iurchenko Date: Mon, 9 Feb 2015 15:07:53 +0000 (+0200) Subject: rgw: Swift API. The second way of specifying desirable response format. X-Git-Tag: v0.93~66 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=6898f0b27f534aee94a87e4dbe128e5e92b7d828;p=ceph.git rgw: Swift API. The second way of specifying desirable response format. 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 Signed-off-by: Dmytro Iurchenko --- diff --git a/src/rgw/rgw_rest.cc b/src/rgw/rgw_rest.cc index b7c07d4e515e..93f5b3f0b26c 100644 --- a/src/rgw/rgw_rest.cc +++ b/src/rgw/rgw_rest.cc @@ -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; + } + } } }