]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
rgw: Swift's FormPost does support per-file content types.
authorRadoslaw Zarzynski <rzarzynski@mirantis.com>
Wed, 21 Sep 2016 17:24:40 +0000 (19:24 +0200)
committerRadoslaw Zarzynski <rzarzynski@mirantis.com>
Mon, 24 Apr 2017 15:32:16 +0000 (17:32 +0200)
Signed-off-by: Radoslaw Zarzynski <rzarzynski@mirantis.com>
src/rgw/rgw_op.cc
src/rgw/rgw_op.h
src/rgw/rgw_rest_s3.cc
src/rgw/rgw_rest_s3.h
src/rgw/rgw_rest_swift.cc
src/rgw/rgw_rest_swift.h

index ab186d80f46ff027ae440205b24db1a7ebf19f1e..d6e07c576320fe4a1497bebb1c9e244f83f839d9 100644 (file)
@@ -3396,8 +3396,9 @@ void RGWPostObj::execute()
     policy.encode(aclbl);
     emplace_attr(RGW_ATTR_ACL, std::move(aclbl));
 
-    if (content_type.size()) {
-      bufferlist ct_bl;
+    const std::string content_type = get_current_content_type();
+    if (! content_type.empty()) {
+      ceph::bufferlist ct_bl;
       ct_bl.append(content_type.c_str(), content_type.size() + 1);
       emplace_attr(RGW_ATTR_CONTENT_TYPE, std::move(ct_bl));
     }
index be5c37f93b6452252b2ccbd35ca62037a3426ec7..a1d36892331634951ffe76cae3e792eb44eec297 100644 (file)
@@ -1013,13 +1013,13 @@ protected:
   const char *supplied_md5_b64;
   const char *supplied_etag;
   string etag;
-  string content_type;
   RGWAccessControlPolicy policy;
   map<string, bufferlist> attrs;
   boost::optional<ceph::real_time> delete_at;
 
   /* Must be called after get_data() or the result is undefined. */
   virtual std::string get_current_filename() const = 0;
+  virtual std::string get_current_content_type() const = 0;
   virtual bool is_next_file_to_upload() {
      return false;
   }
index 4aebd3165bf68ebdcce8a43be380d4dcfd82acee..fc21e746f634a0729d8997a1886eae4bf757d491 100644 (file)
@@ -1514,6 +1514,11 @@ std::string RGWPostObj_ObjStore_S3::get_current_filename() const
   return s->object.name;
 }
 
+std::string RGWPostObj_ObjStore_S3::get_current_content_type() const
+{
+  return content_type;
+}
+
 int RGWPostObj_ObjStore_S3::get_params()
 {
   op_ret = RGWPostObj_ObjStore::get_params();
index 463d6f523683f37a6f6c7aa0e4fad62588823609..1e100efb2c596316825d51d7e2acd6673608f0ca 100644 (file)
@@ -198,6 +198,7 @@ public:
 class RGWPostObj_ObjStore_S3 : public RGWPostObj_ObjStore {
   parts_collection_t parts;
   std::string filename;
+  std::string content_type;
   RGWPolicyEnv env;
   RGWPolicy post_policy;
   map<string, string> crypt_http_responses;
@@ -208,6 +209,8 @@ class RGWPostObj_ObjStore_S3 : public RGWPostObj_ObjStore {
   void rebuild_key(string& key);
 
   std::string get_current_filename() const override;
+  std::string get_current_content_type() const override;
+
 public:
   RGWPostObj_ObjStore_S3() {}
   ~RGWPostObj_ObjStore_S3() override {}
index cd6444c4a4b422a05856a5c2bc8f1e14953def8c..98938e4d05e1ac53ac24862751fb1008a883ed34 100644 (file)
@@ -1901,6 +1901,18 @@ std::string RGWFormPost::get_current_filename() const
   return prefix;
 }
 
+std::string RGWFormPost::get_current_content_type() const
+{
+  try {
+    const auto& field = current_data_part->fields.at("Content-Type");
+    return field.val;
+  } catch (std::out_of_range&) {
+    /* NOP */;
+  }
+
+  return std::string();
+}
+
 bool RGWFormPost::is_next_file_to_upload()
 {
   if (! stream_done) {
index 8032bcf656f6ad401ae44557f8413b62ae3747ca..9f38209deb36d5553454b5a0317be1dfaf84badd 100644 (file)
@@ -242,6 +242,7 @@ public:
 
 class RGWFormPost : public RGWPostObj_ObjStore {
   std::string get_current_filename() const override;
+  std::string get_current_content_type() const override;
   std::size_t get_max_file_size() /*const*/;
   bool is_next_file_to_upload() override;
   bool is_integral();