diff options
author | Boris Kolpackov <boris@codesynthesis.com> | 2015-04-27 13:52:25 +0200 |
---|---|---|
committer | Boris Kolpackov <boris@codesynthesis.com> | 2015-04-27 13:52:25 +0200 |
commit | 04c1324c57692dfd22fab211a7443aaf484f07ce (patch) | |
tree | 9dcc8f36d6d94f02b7c3b2ed1485a50417e3b5e0 /web/apache/request.cxx | |
parent | b4c7f615916cd41e4772c5dc1b2f9f59b3b2ae6c (diff) |
Implement module configuration, cleanup the code
Diffstat (limited to 'web/apache/request.cxx')
-rw-r--r-- | web/apache/request.cxx | 73 |
1 files changed, 32 insertions, 41 deletions
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 <web/apache/request> -#include <stdexcept> +#include <apr_tables.h> + +#include <strings.h> // strcasecmp() + #include <ios> -#include <streambuf> +#include <ctime> +#include <chrono> +#include <memory> // unique_ptr #include <sstream> #include <ostream> -#include <memory> // unique_ptr +#include <cstring> +#include <stdexcept> +#include <streambuf> #include <algorithm> // move() -#include <chrono> -#include <ctime> - -#include <strings.h> // strcasecmp() - -#include <apr_tables.h> 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<std::streambuf> out_buf( - buffer ? static_cast<std::streambuf*> (new std::stringbuf ()) : - static_cast<std::streambuf*> (new ostreambuf (rec_))); + std::unique_ptr<std::streambuf> out_buf ( + buffer + ? static_cast<std::streambuf*> (new std::stringbuf ()) + : static_cast<std::streambuf*> (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"); } |