22 #ifndef INCLUDE_OLA_HTTP_HTTPSERVER_H_
23 #define INCLUDE_OLA_HTTP_HTTPSERVER_H_
27 #include <ola/io/Descriptor.h>
28 #include <ola/io/SelectServer.h>
29 #include <ola/thread/Thread.h>
35 #include <sys/select.h>
36 #include <sys/socket.h>
37 #include <microhttpd.h>
52 const std::string &method,
53 const std::string &version,
54 struct MHD_Connection *connection);
59 const std::string Url()
const {
return m_url; }
60 const std::string Method()
const {
return m_method; }
61 const std::string Version()
const {
return m_version; }
63 void AddHeader(
const std::string &key,
const std::string &value);
66 const std::string
GetHeader(
const std::string &key)
const;
68 const std::string
GetParameter(
const std::string &key)
const;
71 bool InFlight()
const {
return m_in_flight; }
72 void SetInFlight() { m_in_flight =
true; }
77 std::string m_version;
78 struct MHD_Connection *m_connection;
79 std::map<std::string, std::string> m_headers;
80 std::map<std::string, std::string> m_post_params;
81 struct MHD_PostProcessor *m_processor;
84 static const unsigned int K_POST_BUFFER_SIZE = 1024;
95 explicit HTTPResponse(
struct MHD_Connection *connection):
96 m_connection(connection),
97 m_status_code(MHD_HTTP_OK) {}
99 void Append(
const std::string &data) { m_data.append(data); }
101 void SetHeader(
const std::string &key,
const std::string &value);
102 void SetStatus(
unsigned int status) { m_status_code = status; }
106 struct MHD_Connection *Connection()
const {
return m_connection; }
109 struct MHD_Connection *m_connection;
110 typedef std::multimap<std::string, std::string> HeadersMultiMap;
111 HeadersMultiMap m_headers;
112 unsigned int m_status_code;
149 std::string data_dir;
173 bool RegisterHandler(
const std::string &path, BaseHTTPCallback *handler);
177 const std::string &content_type);
179 const std::string &file,
180 const std::string &content_type);
184 void Handlers(std::vector<std::string> *handlers)
const;
185 const std::string DataDir()
const {
return m_data_dir; }
194 const std::string &content_type,
197 static const char CONTENT_TYPE_PLAIN[];
198 static const char CONTENT_TYPE_HTML[];
199 static const char CONTENT_TYPE_GIF[];
200 static const char CONTENT_TYPE_PNG[];
201 static const char CONTENT_TYPE_CSS[];
202 static const char CONTENT_TYPE_JS[];
209 std::string file_path;
210 std::string content_type;
216 struct MHD_Daemon *m_httpd;
220 std::map<std::string, BaseHTTPCallback*> m_handlers;
221 std::map<std::string, static_file_info> m_static_content;
222 BaseHTTPCallback *m_default_handler;
224 std::string m_data_dir;
227 HTTPResponse *response);
237 #endif // INCLUDE_OLA_HTTP_HTTPSERVER_H_