aboutsummaryrefslogtreecommitdiff
path: root/web/apache/service.txx
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2015-05-04 21:22:14 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2015-05-04 21:22:14 +0200
commit63229f465aaea8dd5553814535220817319a64f5 (patch)
tree326ce5cbf4afd118b34ad74d8698a30a23860a42 /web/apache/service.txx
parent73eb44142be85f964a32be00e8ce655f61063d08 (diff)
Cleanup the code
Diffstat (limited to 'web/apache/service.txx')
-rw-r--r--web/apache/service.txx85
1 files changed, 85 insertions, 0 deletions
diff --git a/web/apache/service.txx b/web/apache/service.txx
new file mode 100644
index 0000000..06f3599
--- /dev/null
+++ b/web/apache/service.txx
@@ -0,0 +1,85 @@
+// file : web/apache/service.txx -*- C++ -*-
+// copyright : Copyright (c) 2014-2015 Code Synthesis Tools CC
+// license : MIT; see accompanying LICENSE file
+
+#include <httpd/http_log.h>
+
+#include <exception>
+
+namespace web
+{
+ namespace apache
+ {
+ template <typename M>
+ int service::
+ handle(request& r, log& l) noexcept
+ {
+ static const std::string func_name (
+ "web::apache::service<" + name_ + ">::handle");
+
+ try
+ {
+ M m (static_cast<const M&> (exemplar_));
+ static_cast<module&> (m).handle (r, r, l);
+ return r.flush ();
+ }
+ catch (const invalid_request& e)
+ {
+ if (!e.content.empty () && !r.get_write_state ())
+ {
+ try
+ {
+ r.content (e.status, e.type) << e.content;
+ return r.flush ();
+ }
+ catch (const std::exception& e)
+ {
+ l.write (nullptr, 0, func_name.c_str (), APLOG_ERR, e.what ());
+ }
+ }
+
+ return e.status;
+ }
+ catch (const std::exception& e)
+ {
+ l.write (nullptr, 0, func_name.c_str (), APLOG_ERR, e.what ());
+
+ if (*e.what () && !r.get_write_state ())
+ {
+ try
+ {
+ r.content (HTTP_INTERNAL_SERVER_ERROR, "text/plain;charset=utf-8")
+ << e.what ();
+
+ return r.flush ();
+ }
+ catch (const std::exception& e)
+ {
+ l.write (nullptr, 0, func_name.c_str (), APLOG_ERR, e.what ());
+ }
+ }
+ }
+ catch (...)
+ {
+ l.write (nullptr, 0, func_name.c_str (), APLOG_ERR, "unknown error");
+
+ if (!r.get_write_state ())
+ {
+ try
+ {
+ r.content (HTTP_INTERNAL_SERVER_ERROR, "text/plain;charset=utf-8")
+ << "unknown error";
+
+ return r.flush ();
+ }
+ catch (const std::exception& e)
+ {
+ l.write (nullptr, 0, func_name.c_str (), APLOG_ERR, e.what ());
+ }
+ }
+ }
+
+ return HTTP_INTERNAL_SERVER_ERROR;
+ }
+ }
+}