Open Lighting Architecture
0.9.0
|
The base HTTP Server.
This is a simple HTTP Server built around libmicrohttpd. It runs in a separate thread.
Classes | |
struct | HTTPServerOptions |
struct | static_file_info |
Public Types | |
typedef ola::Callback2< int, const HTTPRequest *, HTTPResponse * > | BaseHTTPCallback |
Public Member Functions | |
HTTPServer (const HTTPServerOptions &options) | |
virtual | ~HTTPServer () |
bool | Init () |
void * | Run () |
void | Stop () |
void | UpdateSockets () |
void | HandleHTTPIO () |
int | DispatchRequest (const HTTPRequest *request, HTTPResponse *response) |
bool | RegisterHandler (const std::string &path, BaseHTTPCallback *handler) |
bool | RegisterFile (const std::string &path, const std::string &content_type) |
bool | RegisterFile (const std::string &path, const std::string &file, const std::string &content_type) |
void | RegisterDefaultHandler (BaseHTTPCallback *handler) |
void | Handlers (std::vector< std::string > *handlers) const |
const std::string | DataDir () const |
int | ServeError (HTTPResponse *response, const std::string &details="") |
int | ServeNotFound (HTTPResponse *response) |
int | ServeStaticContent (const std::string &path, const std::string &content_type, HTTPResponse *response) |
ola::io::SelectServer * | SelectServer () |
Public Member Functions inherited from ola::thread::Thread | |
virtual bool | Start () |
virtual bool | FastStart () |
virtual bool | Join (void *ptr=NULL) |
bool | IsRunning () |
ThreadId | Id () const |
void * | _InternalRun () |
Static Public Member Functions | |
static int | ServeRedirect (HTTPResponse *response, const std::string &location) |
Static Public Member Functions inherited from ola::thread::Thread | |
static ThreadId | Self () |
|
explicit |
Setup the HTTP server.
options | the configuration options for the server |
|
virtual |
Destroy this object
int ola::http::HTTPServer::DispatchRequest | ( | const HTTPRequest * | request, |
HTTPResponse * | response | ||
) |
Call the appropriate handler.
|
inline |
Called when there is HTTP IO activity to deal with. This is a noop as MHD_run is called in UpdateSockets above.
void ola::http::HTTPServer::Handlers | ( | std::vector< std::string > * | handlers | ) | const |
Return a list of all handlers registered
bool ola::http::HTTPServer::Init | ( | ) |
Setup the HTTP server
void ola::http::HTTPServer::RegisterDefaultHandler | ( | BaseHTTPCallback * | handler | ) |
Set the default handler.
handler | the default handler to call. This will be freed when the HTTPServer is destroyed. |
bool ola::http::HTTPServer::RegisterFile | ( | const std::string & | path, |
const std::string & | content_type | ||
) |
Register a static file. The root of the URL corresponds to the data dir.
path | the URL path for the file e.g. '/foo.png' |
content_type | the content type. |
bool ola::http::HTTPServer::RegisterFile | ( | const std::string & | path, |
const std::string & | file, | ||
const std::string & | content_type | ||
) |
Register a static file
path | the path to serve on e.g. /foo.png |
file | the path to the file to serve relative to the data dir e.g. images/foo.png |
content_type | the content type. |
bool ola::http::HTTPServer::RegisterHandler | ( | const std::string & | path, |
BaseHTTPCallback * | handler | ||
) |
Register a handler
path | the url to respond on |
handler | the Closure to call for this request. These will be freed once the HTTPServer is destroyed. |
|
virtual |
The entry point into the new thread
Implements ola::thread::Thread.
int ola::http::HTTPServer::ServeError | ( | HTTPResponse * | response, |
const std::string & | details = "" |
||
) |
Serve an error.
response | the reponse to use. |
details | the error description |
int ola::http::HTTPServer::ServeNotFound | ( | HTTPResponse * | response | ) |
Serve a 404
response | the response to use |
|
static |
Serve a redirect
response | the response to use |
location | the location to redirect to |
int ola::http::HTTPServer::ServeStaticContent | ( | const std::string & | path, |
const std::string & | content_type, | ||
HTTPResponse * | response | ||
) |
Return the contents of a file
void ola::http::HTTPServer::Stop | ( | ) |
Stop the HTTP server
void ola::http::HTTPServer::UpdateSockets | ( | ) |
This is run every loop iteration to update the list of sockets in the SelectServer from MHD.