From: Radoslaw Zarzynski Date: Wed, 21 Sep 2016 17:24:40 +0000 (+0200) Subject: rgw: Swift's FormPost does support per-file content types. X-Git-Tag: v12.0.3~99^2~5 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=61550f3b914f96b37352ff7c9dcd8d0b66b92961;p=ceph.git rgw: Swift's FormPost does support per-file content types. Signed-off-by: Radoslaw Zarzynski --- diff --git a/src/rgw/rgw_op.cc b/src/rgw/rgw_op.cc index ab186d80f46f..d6e07c576320 100644 --- a/src/rgw/rgw_op.cc +++ b/src/rgw/rgw_op.cc @@ -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)); } diff --git a/src/rgw/rgw_op.h b/src/rgw/rgw_op.h index be5c37f93b64..a1d368923316 100644 --- a/src/rgw/rgw_op.h +++ b/src/rgw/rgw_op.h @@ -1013,13 +1013,13 @@ protected: const char *supplied_md5_b64; const char *supplied_etag; string etag; - string content_type; RGWAccessControlPolicy policy; map attrs; boost::optional 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; } diff --git a/src/rgw/rgw_rest_s3.cc b/src/rgw/rgw_rest_s3.cc index 4aebd3165bf6..fc21e746f634 100644 --- a/src/rgw/rgw_rest_s3.cc +++ b/src/rgw/rgw_rest_s3.cc @@ -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(); diff --git a/src/rgw/rgw_rest_s3.h b/src/rgw/rgw_rest_s3.h index 463d6f523683..1e100efb2c59 100644 --- a/src/rgw/rgw_rest_s3.h +++ b/src/rgw/rgw_rest_s3.h @@ -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 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 {} diff --git a/src/rgw/rgw_rest_swift.cc b/src/rgw/rgw_rest_swift.cc index cd6444c4a4b4..98938e4d05e1 100644 --- a/src/rgw/rgw_rest_swift.cc +++ b/src/rgw/rgw_rest_swift.cc @@ -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) { diff --git a/src/rgw/rgw_rest_swift.h b/src/rgw/rgw_rest_swift.h index 8032bcf656f6..9f38209deb36 100644 --- a/src/rgw/rgw_rest_swift.h +++ b/src/rgw/rgw_rest_swift.h @@ -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();