From: Radoslaw Zarzynski Date: Mon, 1 Aug 2016 15:43:01 +0000 (+0200) Subject: rgw: implement RGWStreamIOConLenControllingEngine. X-Git-Tag: v11.1.0~454^2~47 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=c1780267ff42c014edd62c307eb0ed928c3c3c5d;p=ceph.git rgw: implement RGWStreamIOConLenControllingEngine. Signed-off-by: Radoslaw Zarzynski --- diff --git a/src/rgw/rgw_client_io_decoimpl.h b/src/rgw/rgw_client_io_decoimpl.h index 4b0994c106b5..4a1dfe22c86c 100644 --- a/src/rgw/rgw_client_io_decoimpl.h +++ b/src/rgw/rgw_client_io_decoimpl.h @@ -247,9 +247,53 @@ int RGWStreamIOBufferingEngine::complete_request() return sent + RGWDecoratedStreamIO::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 +class RGWStreamIOConLenControllingEngine : public RGWDecoratedStreamIO { +protected: + enum class ContentLengthAction { + FORWARD, + INHIBIT, + UNKNOWN + } action; + +public: + template + RGWStreamIOConLenControllingEngine(U&& decoratee) + : RGWDecoratedStreamIO(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::send_status(status, status_name); + } + + int send_content_length(const uint64_t len) override { + switch(action) { + case ContentLengthAction::FORWARD: + return RGWDecoratedStreamIO::send_content_length(len); + case ContentLengthAction::INHIBIT: + return 0; + case ContentLengthAction::UNKNOWN: + default: + return -EINVAL; + } + } +}; + + template -RGWStreamIOBufferingEngine add_buffering(T&& t) { - return RGWStreamIOBufferingEngine(std::move(t)); +RGWStreamIOConLenControllingEngine add_conlen_controlling(T&& t) { + return RGWStreamIOConLenControllingEngine(std::move(t)); }