From a20443c285dabdec8d2ee740500c62e31ad90c7b Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Thu, 23 Apr 2015 12:43:52 +0200 Subject: Implement apache service --- web/module | 66 +++++++++++++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 57 insertions(+), 9 deletions(-) (limited to 'web/module') diff --git a/web/module b/web/module index 642b1bd..9f1c778 100644 --- a/web/module +++ b/web/module @@ -5,27 +5,49 @@ #ifndef WEB_MODULE #define WEB_MODULE +#include // move() +#include // runtime_error #include #include #include +#include #include // uint16_t -#include // move() -#include // runtime_error namespace web { - // Exception indicating HTTP request/response sequencing error. - // For example, trying to change the status code after some - // content has already been written. - // - struct sequence_error: std::runtime_error {}; - // HTTP status code. // // @@ Define some commonly used constants? // using status_code = std::uint16_t; + // This exception is used to signal that the request is invalid + // (4XX codes) rather than that it could not be processed (5XX). + // By default 400 is returned, which means the request is malformed. + // Non empty description of a caught by the module implementation exception + // can be sent to client in http response body with + // Content-Type:text/html;charset=utf-8 header. + // + struct invalid_request + { + status_code status; + std::string description; + + //@@ Maybe optional "try again" link? + // + invalid_request (status_code s = 400, std::string d = "") + : status (s), description (std::move (d)) {} + }; + + // Exception indicating HTTP request/response sequencing error. + // For example, trying to change the status code after some + // content has already been written. + // + struct sequence_error: std::runtime_error + { + sequence_error (std::string d) : std::runtime_error (d) {} + }; + struct name_value { // These should eventually become string_view's. @@ -48,8 +70,21 @@ namespace web // in name_values. //@@ Maybe parameter_list() and parameter_map()? // + // Throw invalid_request if mime url decode of name or value fail. + // virtual const name_values& parameters () = 0; + + // Throw invalid_request if Cookie header is malformed. + // + virtual const name_values& + cookies () = 0; + + // Get stream to read request body data. + // Throw sequence_error if some unbuffered content is already written. + // + virtual std::istream& + data () = 0; }; class response @@ -75,9 +110,22 @@ namespace web content (status_code, const std::string& type, bool buffer = true) = 0; // Set status code without writing any content. + // On status change discards buffered output and throw sequence_error + // if output were not buffered. // virtual void status (status_code) = 0; + + // Throw sequence_error if some unbuffered content is already written as + // will not be able to send Set-Cookie header. + // + virtual void + cookie (const char* name, + const char* value, + const std::chrono::seconds* max_age = 0, + const char* path = 0, + const char* domain = 0, + bool secure = false) = 0; }; // A web server logging backend. The module can use it to log @@ -91,7 +139,7 @@ namespace web { public: virtual void - write (const char* msg); + write (const char* msg) = 0; }; // The web server creates a new module instance for each request -- cgit v1.1