]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
rgw: implement RGWStreamIOConLenControllingEngine.
authorRadoslaw Zarzynski <rzarzynski@mirantis.com>
Mon, 1 Aug 2016 15:43:01 +0000 (17:43 +0200)
committerRadoslaw Zarzynski <rzarzynski@mirantis.com>
Fri, 21 Oct 2016 20:57:18 +0000 (22:57 +0200)
Signed-off-by: Radoslaw Zarzynski <rzarzynski@mirantis.com>
src/rgw/rgw_client_io_decoimpl.h

index 4b0994c106b50d64e461a2ed98cad1cfe90f1fc4..4a1dfe22c86cf3e5ded7ba38f35d6b5e6bccea88 100644 (file)
@@ -247,9 +247,53 @@ int RGWStreamIOBufferingEngine<T>::complete_request()
   return sent + RGWDecoratedStreamIO<T>::complete_request();
 }
 
+
+/* Class that controls and inhibits the process of sending Content-Length HTTP
+ * header where RFC 7230 requests so. The cases worth our attention are 204 No
+ * Content as well as 304 Not Modified. */
+template <typename T>
+class RGWStreamIOConLenControllingEngine : public RGWDecoratedStreamIO<T> {
+protected:
+  enum class ContentLengthAction {
+    FORWARD,
+    INHIBIT,
+    UNKNOWN
+  } action;
+
+public:
+  template <typename U>
+  RGWStreamIOConLenControllingEngine(U&& decoratee)
+    : RGWDecoratedStreamIO<T>(std::move(decoratee)),
+      action(ContentLengthAction::UNKNOWN) {
+  }
+
+  int send_status(const int status, const char* const status_name) override {
+    if (204 == status || 304 == status) {
+      action = ContentLengthAction::INHIBIT;
+    } else {
+      action = ContentLengthAction::FORWARD;
+    }
+
+    return RGWDecoratedStreamIO<T>::send_status(status, status_name);
+  }
+
+  int send_content_length(const uint64_t len) override {
+    switch(action) {
+    case ContentLengthAction::FORWARD:
+      return RGWDecoratedStreamIO<T>::send_content_length(len);
+    case ContentLengthAction::INHIBIT:
+      return 0;
+    case ContentLengthAction::UNKNOWN:
+    default:
+      return -EINVAL;
+    }
+  }
+};
+
+
 template <typename T>
-RGWStreamIOBufferingEngine<T> add_buffering(T&& t) {
-  return RGWStreamIOBufferingEngine<T>(std::move(t));
+RGWStreamIOConLenControllingEngine<T> add_conlen_controlling(T&& t) {
+  return RGWStreamIOConLenControllingEngine<T>(std::move(t));
 }