From 04c1324c57692dfd22fab211a7443aaf484f07ce Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Mon, 27 Apr 2015 13:52:25 +0200 Subject: Implement module configuration, cleanup the code --- web/apache/request.cxx | 73 ++++++++++++++++++++++---------------------------- 1 file changed, 32 insertions(+), 41 deletions(-) (limited to 'web/apache/request.cxx') diff --git a/web/apache/request.cxx b/web/apache/request.cxx index 6f043bc..1990fa2 100644 --- a/web/apache/request.cxx +++ b/web/apache/request.cxx @@ -4,19 +4,20 @@ #include -#include +#include + +#include // strcasecmp() + #include -#include +#include +#include +#include // unique_ptr #include #include -#include // unique_ptr +#include +#include +#include #include // move() -#include -#include - -#include // strcasecmp() - -#include using namespace std; @@ -47,17 +48,19 @@ namespace web if (e && e < v) v = 0; - string name ( - v ? mime_url_decode (n, v, true) : - (e ? mime_url_decode (n, e, true) : - mime_url_decode (n, n + strlen (n), true))); + string name (v + ? mime_url_decode (n, v, true) + : (e + ? mime_url_decode (n, e, true) + : mime_url_decode (n, n + strlen (n), true))); string value; if (v++) { - value = e ? mime_url_decode (v, e, true) : - mime_url_decode (v, v + strlen (v), true); + value = e + ? mime_url_decode (v, e, true) + : mime_url_decode (v, v + strlen (v), true); } if (!name.empty () || !value.empty ()) @@ -75,31 +78,18 @@ namespace web ostream& request:: content (status_code status, const std::string& type, bool buffer) { - if (type.empty ()) + if (out_ && status == rec_->status && buffer == buffer_ && + !::strcasecmp (rec_->content_type ? rec_->content_type : "", + type.c_str ())) { - // Getting content stream for writing assumes type to be provided. - // - throw std::invalid_argument ( - "::web::apache::request::content invalid type"); + return *out_; } - // Due to apache implementation of error custom response there is no - // way to make it unbuffered. - // - buffer = buffer || status != HTTP_OK; - - if ((status != status_ || type != type_ || buffer != buffer_) & - write_flag ()) + if (get_write_state ()) { throw sequence_error ("::web::apache::request::content"); } - if (status == status_ && type == type_ && buffer == buffer_) - { - assert (out_); - return *out_; - } - if (!buffer) // Request body will be discarded prior first byte of content is // written. Save form data now to make it available for furture @@ -107,9 +97,10 @@ namespace web // form_data (); - std::unique_ptr out_buf( - buffer ? static_cast (new std::stringbuf ()) : - static_cast (new ostreambuf (rec_))); + std::unique_ptr out_buf ( + buffer + ? static_cast (new std::stringbuf ()) + : static_cast (new ostreambuf (rec_, *this))); out_.reset (new std::ostream (out_buf.get ())); @@ -118,12 +109,12 @@ namespace web out_->exceptions ( std::ios::eofbit | std::ios::failbit | std::ios::badbit); - status_ = status; - type_ = type; buffer_ = buffer; + rec_->status = status; - if (!buffer_) - set_content_type (); + ap_set_content_type ( + rec_, + type.empty () ? nullptr : apr_pstrdup (rec_->pool, type.c_str ())); return *out_; } @@ -136,7 +127,7 @@ namespace web const char* domain, bool secure) { - if (write_flag ()) + if (get_write_state ()) { throw sequence_error ("::web::apache::request::cookie"); } -- cgit v1.1