aboutsummaryrefslogtreecommitdiff
path: root/web/apache/request.ixx
diff options
context:
space:
mode:
authorKaren Arutyunov <karen@codesynthesis.com>2016-03-14 14:38:45 +0300
committerKaren Arutyunov <karen@codesynthesis.com>2016-03-17 12:59:35 +0300
commit0b6b57f9acaa2ec648bf582ff67851331f8e6eef (patch)
tree7ce5da6a1c37f3674762d5514b0a34bf05e38df7 /web/apache/request.ixx
parent637d5650b91cb1da2605e5f7049ccc8bab5591f3 (diff)
Use serializable transaction isolation level
Diffstat (limited to 'web/apache/request.ixx')
-rw-r--r--web/apache/request.ixx43
1 files changed, 23 insertions, 20 deletions
diff --git a/web/apache/request.ixx b/web/apache/request.ixx
index 8a3b32b..821aaba 100644
--- a/web/apache/request.ixx
+++ b/web/apache/request.ixx
@@ -4,10 +4,12 @@
#include <strings.h> // strncasecmp()
-#include <iomanip>
+#include <apr_tables.h> // apr_table_*
+
+#include <http_protocol.h> // ap_*()
+
#include <sstream>
-#include <cstring>
-#include <cstdlib>
+#include <utility> // move()
namespace web
{
@@ -16,35 +18,34 @@ namespace web
inline int request::
flush ()
{
- if (buffer_ && out_buf_)
+ if (std::stringbuf* b = dynamic_cast<std::stringbuf*> (out_buf_.get ()))
{
- auto b (dynamic_cast<std::stringbuf*> (out_buf_.get ()));
- assert (b);
-
+ // Response content is buffered.
+ //
std::string s (b->str ());
if (!s.empty ())
{
- // Before writing response read and discard request body if any.
- //
- int r (ap_discard_request_body (rec_));
-
- if (r == OK)
+ try
{
- set_write_state ();
+ state (request_state::writing);
if (ap_rwrite (s.c_str (), s.length (), rec_) < 0)
rec_->status = HTTP_REQUEST_TIME_OUT;
}
- else
- rec_->status = r;
+ catch (const invalid_request& e)
+ {
+ rec_->status = e.status;
+ }
}
out_.reset ();
out_buf_.reset ();
}
- return rec_->status == HTTP_OK || get_write_state () ? OK : rec_->status;
+ return rec_->status == HTTP_OK || state_ >= request_state::writing
+ ? OK
+ : rec_->status;
}
inline const std::string& request::
@@ -64,19 +65,21 @@ namespace web
std::istream& istr (content ());
// Do not throw when eofbit is set (end of stream reached), and
- // when failbit is set (getline() failed to extract any character).
+ // when failbit is set (getline() failed to extract any
+ // character).
//
- istr.exceptions (std::ios::badbit);
+ istr.exceptions (std::istream::badbit);
std::getline (istr, *form_data_);
- // Make this data the content of the input stream.
+ // Make this data the content of the input stream, so it's
+ // available for the application as well.
//
std::unique_ptr<std::streambuf> in_buf (
new std::stringbuf (*form_data_));
in_.reset (new std::istream (in_buf.get ()));
in_buf_ = std::move (in_buf);
- in_->exceptions (std::ios::failbit | std::ios::badbit);
+ in_->exceptions (std::istream::failbit | std::istream::badbit);
}
}
}