]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
rgw: rework quoting value of HTTP headers.
authorRadoslaw Zarzynski <rzarzynski@mirantis.com>
Tue, 4 Oct 2016 08:00:00 +0000 (10:00 +0200)
committerRadoslaw Zarzynski <rzarzynski@mirantis.com>
Fri, 21 Oct 2016 20:57:20 +0000 (22:57 +0200)
Signed-off-by: Radoslaw Zarzynski <rzarzynski@mirantis.com>
src/rgw/rgw_rest.cc
src/rgw/rgw_rest.h
src/rgw/rgw_rest_swift.cc

index 317db30b9c6bd3ebac404039b13f81de6f198ea8..37555b9a052b831cf7a3da7145c7d0de501cc733 100644 (file)
@@ -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);
   }
 }
 
index d96886c174ed484875a627c74c76a531fd2fa368..01413ae72ab6312f480d63a940ab57c55f201746 100644 (file)
@@ -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<int>(name_prefix.length()),
+                            name_prefix.data(),
+                            static_cast<int>(name.length()),
+                            name.data());
   boost::string_ref full_name(full_name_buf, len);
   return dump_header(s, std::move(full_name), std::forward<Args>(args)...);
 }
+
+template <class... Args>
+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<int>(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);
index e601439a4ec86731c2d6f8c346e3711e3f936a6b..5f8c553002eb446b666f1d2f57f45c9756a82c40 100644 (file)
@@ -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()) {