From 6be5bc707876ece1cd09d7c304ba559512ef5257 Mon Sep 17 00:00:00 2001 From: Karen Arutyunov Date: Wed, 19 Apr 2017 20:48:09 +0300 Subject: Implement request body caching --- web/apache/request | 32 ++++++++++++++++++++++++-------- 1 file changed, 24 insertions(+), 8 deletions(-) (limited to 'web/apache/request') diff --git a/web/apache/request b/web/apache/request index 7f8cf8c..a35c5dc 100644 --- a/web/apache/request +++ b/web/apache/request @@ -50,17 +50,23 @@ namespace web writing }; + // Extends istreambuf with read limit checking, caching, etc. (see the + // implementation for details). + // + class istreambuf_cache; + class request: public web::request, public web::response, public stream_state { friend class service; - request (request_rec* rec) noexcept - : rec_ (rec) - { - rec_->status = HTTP_OK; - } + // Can not be inline/default due to the member of + // unique_ptr type. Note that istreambuf_cache type is + // incomplete. + // + request (request_rec* rec) noexcept; + ~request (); request_state state () const noexcept {return state_;} @@ -87,7 +93,7 @@ namespace web // Get request body data stream. // virtual std::istream& - content (bool buffer = false); + content (size_t limit = 0, size_t buffer = 0); // Get request parameters. // @@ -128,7 +134,10 @@ namespace web bool buffer = true); private: - // Get application/x-www-form-urlencoded form data. + // Get application/x-www-form-urlencoded form data. If request::content() + // was not called yet (and so limits are not specified) then set both of + // them to 64KB. Rewind the stream afterwards, so it's available for the + // application as well, unless no buffering were requested beforehand. // const std::string& form_data (); @@ -152,6 +161,12 @@ namespace web virtual void set_write_state () {state (request_state::writing);} + // Rewind the input stream (that must exist). Throw sequence_error if + // some unbuffered content have already been read. + // + void + rewind_istream (); + private: request_rec* rec_; request_state state_ = request_state::initial; @@ -160,7 +175,8 @@ namespace web std::unique_ptr parameters_; std::unique_ptr cookies_; std::unique_ptr form_data_; - std::unique_ptr in_buf_; + + std::unique_ptr in_buf_; std::unique_ptr in_; std::unique_ptr out_buf_; -- cgit v1.1