Go to the documentation of this file.00001 #ifndef CPP_WEB_SERVER_HTTP_REQUEST_HANDLER_HPP
00002 #define CPP_WEB_SERVER_HTTP_REQUEST_HANDLER_HPP
00003
00004 #include <boost/function.hpp>
00005 #include <boost/shared_ptr.hpp>
00006 #include "async_web_server_cpp/http_request.hpp"
00007
00008 namespace async_web_server_cpp
00009 {
00010
00011 class HttpConnection;
00012
00019 typedef boost::function<bool(const HttpRequest &, boost::shared_ptr<HttpConnection>, const char* begin, const char* end)> HttpServerRequestHandler;
00020
00026 class HttpRequestHandlerGroup
00027 {
00028 public:
00029 typedef boost::function<bool(const HttpRequest &)> HandlerPredicate;
00030
00031 HttpRequestHandlerGroup(HttpServerRequestHandler default_handler);
00032
00033 void addHandlerForPath(const std::string &path_regex, HttpServerRequestHandler handler);
00034
00035 void addHandler(HandlerPredicate predicate, HttpServerRequestHandler handler);
00036
00037 bool operator()(const HttpRequest &request, boost::shared_ptr<HttpConnection> connection, const char* begin, const char* end);
00038
00039 private:
00040 HttpServerRequestHandler default_handler_;
00041 std::vector<std::pair<HandlerPredicate, HttpServerRequestHandler> > handlers_;
00042 };
00043
00044 class HttpRequestBodyCollector
00045 {
00046 public:
00047 typedef boost::function<void(const HttpRequest &, boost::shared_ptr<HttpConnection>, const std::string& body)> Handler;
00048
00049 HttpRequestBodyCollector(Handler handler);
00050
00051 bool operator()(const HttpRequest &request, boost::shared_ptr<HttpConnection> connection, const char* begin, const char* end);
00052
00053 private:
00054 Handler handler_;
00055 };
00056
00057 }
00058
00059 #endif