http_reply.hpp
Go to the documentation of this file.
00001 #ifndef CPP_WEB_SERVER_HTTP_REPLY_HPP
00002 #define CPP_WEB_SERVER_HTTP_REPLY_HPP
00003 
00004 #include <vector>
00005 #include <string>
00006 #include <boost/asio.hpp>
00007 #include "async_web_server_cpp/http_header.hpp"
00008 #include "async_web_server_cpp/http_connection.hpp"
00009 #include "async_web_server_cpp/http_request_handler.hpp"
00010 
00011 namespace async_web_server_cpp
00012 {
00013 
00014 class ReplyBuilder;
00015 
00019 struct HttpReply
00020 {
00021   enum status_type
00022   {
00023     switching_protocols = 101,
00024     ok = 200,
00025     created = 201,
00026     accepted = 202,
00027     no_content = 204,
00028     multiple_choices = 300,
00029     moved_permanently = 301,
00030     moved_temporarily = 302,
00031     not_modified = 304,
00032     bad_request = 400,
00033     unauthorized = 401,
00034     forbidden = 403,
00035     not_found = 404,
00036     internal_server_error = 500,
00037     not_implemented = 501,
00038     bad_gateway = 502,
00039     service_unavailable = 503
00040   } status;
00041 
00042   static std::vector<boost::asio::const_buffer> to_buffers(const std::vector<HttpHeader> &headers);
00043 
00047   static HttpServerRequestHandler stock_reply(status_type status);
00048 
00053   static HttpServerRequestHandler from_file(HttpReply::status_type status,
00054       const std::string& content_type,
00055       const std::string& filename,
00056       const std::vector<HttpHeader>& additional_headers = std::vector<HttpHeader>());
00057 
00061   static HttpServerRequestHandler static_reply(status_type status,
00062       const std::string& content_type,
00063       const std::string& content,
00064       const std::vector<HttpHeader>& additional_headers = std::vector<HttpHeader>());
00065 
00069   static ReplyBuilder builder(status_type status);
00070 };
00071 
00075 class ReplyBuilder
00076 {
00077 public:
00078   ReplyBuilder(HttpReply::status_type status);
00079 
00083   ReplyBuilder &header(const std::string &name, const std::string &value);
00084 
00088   ReplyBuilder &header(const HttpHeader &header);
00089 
00093   ReplyBuilder &headers(const std::vector<HttpHeader> &headers);
00094 
00098   void write(HttpConnectionPtr connection);
00099 
00100 private:
00101   HttpReply::status_type status_;
00102   boost::shared_ptr<std::vector<HttpHeader> > headers_;
00103 };
00104 
00105 
00109 class StaticHttpRequestHandler
00110 {
00111 public:
00112   StaticHttpRequestHandler(HttpReply::status_type status,
00113                            const std::vector<HttpHeader> &headers,
00114                            const std::string &content);
00115 
00116   void operator()(const HttpRequest &, boost::shared_ptr<HttpConnection>, const char* begin, const char* end);
00117 
00118 private:
00119   ReplyBuilder reply_builder_;
00120   const std::string content_string_;
00121 };
00122 
00123 }
00124 
00125 #endif


async_web_server_cpp
Author(s): Mitchell Wills
autogenerated on Thu Aug 27 2015 12:27:39