http_reply.hpp
Go to the documentation of this file.
1 #ifndef CPP_WEB_SERVER_HTTP_REPLY_HPP
2 #define CPP_WEB_SERVER_HTTP_REPLY_HPP
3 
7 
8 #include <boost/asio.hpp>
9 #include <boost/filesystem.hpp>
10 
11 #include <string>
12 #include <vector>
13 
14 namespace async_web_server_cpp
15 {
16 
17 class ReplyBuilder;
18 
22 struct HttpReply
23 {
25  {
27  ok = 200,
28  created = 201,
29  accepted = 202,
30  no_content = 204,
34  not_modified = 304,
35  bad_request = 400,
36  unauthorized = 401,
37  forbidden = 403,
38  not_found = 404,
41  bad_gateway = 502,
43  } status;
44 
45  static std::vector<boost::asio::const_buffer>
46  to_buffers(const std::vector<HttpHeader>& headers);
47 
52 
57  from_file(HttpReply::status_type status, const std::string& content_type,
58  const std::string& filename,
59  const std::vector<HttpHeader>& additional_headers =
60  std::vector<HttpHeader>());
61 
70  from_filesystem(HttpReply::status_type status, const std::string& path_root,
71  const std::string& filesystem_root, bool list_directories,
72  const std::vector<HttpHeader>& additional_headers =
73  std::vector<HttpHeader>());
74 
79  static_reply(status_type status, const std::string& content_type,
80  const std::string& content,
81  const std::vector<HttpHeader>& additional_headers =
82  std::vector<HttpHeader>());
83 
88 };
89 
94 {
95 public:
97 
101  ReplyBuilder& header(const std::string& name, const std::string& value);
102 
107 
111  ReplyBuilder& headers(const std::vector<HttpHeader>& headers);
112 
116  void write(HttpConnectionPtr connection);
117 
118 private:
120  boost::shared_ptr<std::vector<HttpHeader>> headers_;
121 };
122 
127 {
128 public:
130  const std::vector<HttpHeader>& headers,
131  const std::string& content);
132 
133  bool operator()(const HttpRequest&, boost::shared_ptr<HttpConnection>,
134  const char* begin, const char* end);
135 
136 private:
138  const std::string content_string_;
139 };
140 
145 {
146 public:
148  const std::string& filename,
149  const std::vector<HttpHeader>& headers);
150 
151  bool operator()(const HttpRequest&, boost::shared_ptr<HttpConnection>,
152  const char* begin, const char* end);
153 
154 private:
156  std::vector<HttpHeader> headers_;
157  std::string filename_;
158 };
159 
164 {
165 public:
167  const std::string& path_root,
168  const std::string& filesystem_root,
169  bool list_directories,
170  const std::vector<HttpHeader>& headers);
171 
172  bool operator()(const HttpRequest&, boost::shared_ptr<HttpConnection>,
173  const char* begin, const char* end);
174 
175 private:
177  std::vector<HttpHeader> headers_;
178  std::string path_root_;
179  boost::filesystem::path filesystem_root_;
181 };
182 
183 } // namespace async_web_server_cpp
184 
185 #endif
async_web_server_cpp::FilesystemHttpRequestHandler::FilesystemHttpRequestHandler
FilesystemHttpRequestHandler(HttpReply::status_type status, const std::string &path_root, const std::string &filesystem_root, bool list_directories, const std::vector< HttpHeader > &headers)
Definition: http_reply.cpp:322
http_request_handler.hpp
async_web_server_cpp::HttpReply::status_type
status_type
Definition: http_reply.hpp:24
async_web_server_cpp::FilesystemHttpRequestHandler::status_
HttpReply::status_type status_
Definition: http_reply.hpp:176
async_web_server_cpp::HttpReply::accepted
@ accepted
Definition: http_reply.hpp:29
async_web_server_cpp::FileHttpRequestHandler::FileHttpRequestHandler
FileHttpRequestHandler(HttpReply::status_type status, const std::string &filename, const std::vector< HttpHeader > &headers)
Definition: http_reply.cpp:249
async_web_server_cpp::HttpReply::moved_temporarily
@ moved_temporarily
Definition: http_reply.hpp:33
async_web_server_cpp::ReplyBuilder::header
ReplyBuilder & header(const std::string &name, const std::string &value)
Definition: http_reply.cpp:457
async_web_server_cpp::FilesystemHttpRequestHandler
Definition: http_reply.hpp:163
http_connection.hpp
async_web_server_cpp::FileHttpRequestHandler::headers_
std::vector< HttpHeader > headers_
Definition: http_reply.hpp:156
async_web_server_cpp::HttpHeader
Definition: http_header.hpp:12
async_web_server_cpp::FileHttpRequestHandler::status_
HttpReply::status_type status_
Definition: http_reply.hpp:155
async_web_server_cpp::HttpServerRequestHandler
boost::function< bool(const HttpRequest &, boost::shared_ptr< HttpConnection >, const char *begin, const char *end)> HttpServerRequestHandler
Definition: http_request_handler.hpp:12
async_web_server_cpp::HttpReply::forbidden
@ forbidden
Definition: http_reply.hpp:37
async_web_server_cpp::ReplyBuilder::ReplyBuilder
ReplyBuilder(HttpReply::status_type status)
Definition: http_reply.cpp:452
async_web_server_cpp::HttpReply::service_unavailable
@ service_unavailable
Definition: http_reply.hpp:42
async_web_server_cpp::FilesystemHttpRequestHandler::list_directories_
bool list_directories_
Definition: http_reply.hpp:180
async_web_server_cpp::StaticHttpRequestHandler::operator()
bool operator()(const HttpRequest &, boost::shared_ptr< HttpConnection >, const char *begin, const char *end)
Definition: http_reply.cpp:438
async_web_server_cpp::StaticHttpRequestHandler::content_string_
const std::string content_string_
Definition: http_reply.hpp:138
async_web_server_cpp::FileHttpRequestHandler::operator()
bool operator()(const HttpRequest &, boost::shared_ptr< HttpConnection >, const char *begin, const char *end)
Definition: http_reply.cpp:307
http_header.hpp
async_web_server_cpp::FilesystemHttpRequestHandler::path_root_
std::string path_root_
Definition: http_reply.hpp:178
async_web_server_cpp::HttpReply::no_content
@ no_content
Definition: http_reply.hpp:30
async_web_server_cpp::StaticHttpRequestHandler
Definition: http_reply.hpp:126
async_web_server_cpp
Definition: http_connection.hpp:14
async_web_server_cpp::ReplyBuilder::status_
HttpReply::status_type status_
Definition: http_reply.hpp:119
async_web_server_cpp::FilesystemHttpRequestHandler::headers_
std::vector< HttpHeader > headers_
Definition: http_reply.hpp:177
async_web_server_cpp::HttpReply::stock_reply
static HttpServerRequestHandler stock_reply(status_type status)
Definition: http_reply.cpp:410
async_web_server_cpp::HttpReply::multiple_choices
@ multiple_choices
Definition: http_reply.hpp:31
async_web_server_cpp::FilesystemHttpRequestHandler::filesystem_root_
boost::filesystem::path filesystem_root_
Definition: http_reply.hpp:179
async_web_server_cpp::HttpReply
Definition: http_reply.hpp:22
async_web_server_cpp::FilesystemHttpRequestHandler::operator()
bool operator()(const HttpRequest &, boost::shared_ptr< HttpConnection >, const char *begin, const char *end)
Definition: http_reply.cpp:331
async_web_server_cpp::HttpReply::unauthorized
@ unauthorized
Definition: http_reply.hpp:36
async_web_server_cpp::HttpReply::bad_gateway
@ bad_gateway
Definition: http_reply.hpp:41
async_web_server_cpp::HttpRequest
Definition: http_request.hpp:18
async_web_server_cpp::HttpReply::moved_permanently
@ moved_permanently
Definition: http_reply.hpp:32
async_web_server_cpp::HttpReply::switching_protocols
@ switching_protocols
Definition: http_reply.hpp:26
async_web_server_cpp::ReplyBuilder
Definition: http_reply.hpp:93
async_web_server_cpp::FileHttpRequestHandler::filename_
std::string filename_
Definition: http_reply.hpp:157
async_web_server_cpp::HttpReply::internal_server_error
@ internal_server_error
Definition: http_reply.hpp:39
async_web_server_cpp::HttpReply::created
@ created
Definition: http_reply.hpp:28
async_web_server_cpp::HttpReply::from_file
static HttpServerRequestHandler from_file(HttpReply::status_type status, const std::string &content_type, const std::string &filename, const std::vector< HttpHeader > &additional_headers=std::vector< HttpHeader >())
Definition: http_reply.cpp:237
async_web_server_cpp::HttpConnectionPtr
boost::shared_ptr< HttpConnection > HttpConnectionPtr
Definition: http_connection.hpp:17
async_web_server_cpp::ReplyBuilder::headers_
boost::shared_ptr< std::vector< HttpHeader > > headers_
Definition: http_reply.hpp:120
async_web_server_cpp::HttpReply::builder
static ReplyBuilder builder(status_type status)
Definition: http_reply.cpp:447
async_web_server_cpp::ReplyBuilder::write
void write(HttpConnectionPtr connection)
Definition: http_reply.cpp:475
async_web_server_cpp::ReplyBuilder::headers
ReplyBuilder & headers(const std::vector< HttpHeader > &headers)
Definition: http_reply.cpp:469
async_web_server_cpp::HttpReply::status
enum async_web_server_cpp::HttpReply::status_type status
async_web_server_cpp::HttpReply::static_reply
static HttpServerRequestHandler static_reply(status_type status, const std::string &content_type, const std::string &content, const std::vector< HttpHeader > &additional_headers=std::vector< HttpHeader >())
Definition: http_reply.cpp:416
async_web_server_cpp::HttpReply::to_buffers
static std::vector< boost::asio::const_buffer > to_buffers(const std::vector< HttpHeader > &headers)
Definition: http_reply.cpp:220
async_web_server_cpp::HttpReply::not_modified
@ not_modified
Definition: http_reply.hpp:34
async_web_server_cpp::HttpReply::from_filesystem
static HttpServerRequestHandler from_filesystem(HttpReply::status_type status, const std::string &path_root, const std::string &filesystem_root, bool list_directories, const std::vector< HttpHeader > &additional_headers=std::vector< HttpHeader >())
Definition: http_reply.cpp:314
async_web_server_cpp::FileHttpRequestHandler
Definition: http_reply.hpp:144
async_web_server_cpp::HttpReply::not_found
@ not_found
Definition: http_reply.hpp:38
async_web_server_cpp::StaticHttpRequestHandler::StaticHttpRequestHandler
StaticHttpRequestHandler(HttpReply::status_type status, const std::vector< HttpHeader > &headers, const std::string &content)
Definition: http_reply.cpp:430
async_web_server_cpp::HttpReply::bad_request
@ bad_request
Definition: http_reply.hpp:35
async_web_server_cpp::HttpReply::ok
@ ok
Definition: http_reply.hpp:27
async_web_server_cpp::HttpReply::not_implemented
@ not_implemented
Definition: http_reply.hpp:40
async_web_server_cpp::StaticHttpRequestHandler::reply_builder_
ReplyBuilder reply_builder_
Definition: http_reply.hpp:137


async_web_server_cpp
Author(s): Mitchell Wills , Russel Toris
autogenerated on Tue Mar 1 2022 23:49:06