From 6898f0b27f534aee94a87e4dbe128e5e92b7d828 Mon Sep 17 00:00:00 2001 From: Dmytro Iurchenko Date: Mon, 9 Feb 2015 17:07:53 +0200 Subject: [PATCH] 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 --- src/rgw/rgw_rest.cc | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/rgw/rgw_rest.cc b/src/rgw/rgw_rest.cc index b7c07d4e515..93f5b3f0b26 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; + } + } } } -- 2.47.3