From: Radoslaw Zarzynski Date: Tue, 4 Oct 2016 08:00:00 +0000 (+0200) Subject: rgw: rework quoting value of HTTP headers. X-Git-Tag: v11.1.0~454^2~27 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=c71c652aef9c87fe088a16fff3d3b522d241a2d3;p=ceph.git rgw: rework quoting value of HTTP headers. Signed-off-by: Radoslaw Zarzynski --- diff --git a/src/rgw/rgw_rest.cc b/src/rgw/rgw_rest.cc index 317db30b9c6b..37555b9a052b 100644 --- a/src/rgw/rgw_rest.cc +++ b/src/rgw/rgw_rest.cc @@ -419,26 +419,27 @@ void dump_content_length(struct req_state* const s, const uint64_t len) dump_header(s, "Accept-Ranges", "bytes"); } -void dump_etag(struct req_state* const s, const boost::string_ref& etag) +void dump_etag(struct req_state* const s, + const boost::string_ref& etag, + const bool quoted) { if (etag.empty()) { return; } - if (s->prot_flags & RGW_REST_SWIFT) { + if (s->prot_flags & RGW_REST_SWIFT && ! quoted) { return dump_header(s, "etag", etag); } else { - /* We need two extra bytes for quotes. */ - char buf[etag.size() + 2 + 1]; - const auto len = snprintf(buf, sizeof(buf), "\"%s\"", etag.data()); - - return dump_header(s, "ETag", boost::string_ref(buf, len)); + return dump_header_quoted(s, "ETag", etag); } } -void dump_etag(struct req_state* const s, ceph::buffer::list& bl_etag) +void dump_etag(struct req_state* const s, + ceph::buffer::list& bl_etag, + const bool quoted) { - return dump_etag(s, boost::string_ref(bl_etag.c_str(), bl_etag.length())); + return dump_etag(s, boost::string_ref(bl_etag.c_str(), bl_etag.length()), + quoted); } void dump_pair(struct req_state* const s, @@ -487,7 +488,7 @@ void dump_uri_from_state(struct req_state *s) } } } else { - dump_header(s, "Location", "\"" + s->info.request_uri + "\""); + dump_header_quoted(s, "Location", s->info.request_uri); } } diff --git a/src/rgw/rgw_rest.h b/src/rgw/rgw_rest.h index d96886c174ed..01413ae72ab6 100644 --- a/src/rgw/rgw_rest.h +++ b/src/rgw/rgw_rest.h @@ -550,14 +550,32 @@ static inline void dump_header_prefixed(struct req_state* s, Args&&... args) { char full_name_buf[name_prefix.size() + name.size() + 1]; const auto len = snprintf(full_name_buf, sizeof(full_name_buf), "%.*s%.*s", - name_prefix.length(), name_prefix.data(), - name.length(), name.data()); + static_cast(name_prefix.length()), + name_prefix.data(), + static_cast(name.length()), + name.data()); boost::string_ref full_name(full_name_buf, len); return dump_header(s, std::move(full_name), std::forward(args)...); } + +template +static inline void dump_header_quoted(struct req_state* s, + const boost::string_ref& name, + const boost::string_ref& val) { + /* We need two extra bytes for quotes. */ + char qvalbuf[val.size() + 2 + 1]; + const auto len = snprintf(qvalbuf, sizeof(qvalbuf), "\"%.*s\"", + static_cast(val.length()), val.data()); + return dump_header(s, name, boost::string_ref(qvalbuf, len)); +} + extern void dump_content_length(struct req_state *s, uint64_t len); -extern void dump_etag(struct req_state *s, const boost::string_ref& etag); -extern void dump_etag(struct req_state *s, ceph::buffer::list& bl_etag); +extern void dump_etag(struct req_state *s, + const boost::string_ref& etag, + bool quoted = false); +extern void dump_etag(struct req_state *s, + ceph::buffer::list& bl_etag, + bool quoted = false); extern void dump_epoch_header(struct req_state *s, const char *name, real_time t); extern void dump_time_header(struct req_state *s, const char *name, real_time t); extern void dump_last_modified(struct req_state *s, real_time t); diff --git a/src/rgw/rgw_rest_swift.cc b/src/rgw/rgw_rest_swift.cc index e601439a4ec8..5f8c553002eb 100644 --- a/src/rgw/rgw_rest_swift.cc +++ b/src/rgw/rgw_rest_swift.cc @@ -797,7 +797,7 @@ void RGWPutObj_ObjStore_SWIFT::send_response() op_ret = STATUS_CREATED; } - if (!lo_etag.empty()) { + if (! lo_etag.empty()) { /* Static Large Object of Swift API has two etags represented by * following members: * - etag - for the manifest itself (it will be stored in xattrs), @@ -806,7 +806,7 @@ void RGWPutObj_ObjStore_SWIFT::send_response() * In response for PUT request we have to expose the second one. * The first one may be obtained by GET with "multipart-manifest=get" * in query string on a given SLO. */ - dump_etag(s, ("\"" + lo_etag + "\"")); + dump_etag(s, lo_etag, true /* quoted */); } else { dump_etag(s, etag); } @@ -1278,8 +1278,8 @@ int RGWGetObj_ObjStore_SWIFT::send_response_data(bufferlist& bl, } if (! op_ret) { - if (!lo_etag.empty()) { - dump_etag(s, ("\"" + lo_etag + "\"")); + if (! lo_etag.empty()) { + dump_etag(s, lo_etag, true /* quoted */); } else { auto iter = attrs.find(RGW_ATTR_ETAG); if (iter != attrs.end()) {