web: Page not found handling, sends a 404 error. [Firehawke]

This commit is contained in:
R. Belmont 2013-10-20 05:24:49 +00:00
parent 9a6193eca6
commit 715ba22b0c
2 changed files with 21 additions and 0 deletions

View File

@ -335,6 +335,25 @@ static int begin_request_handler_static(struct mg_connection *conn)
return engine->begin_request_handler(conn);
}
static int begin_http_error_handler_static(struct mg_connection *conn, int status)
{
const struct mg_request_info *request_info = mg_get_request_info(conn);
if (status == 404) // 404 -- File Not Found
{
{
mg_printf(conn,
"HTTP/1.1 404 Not Found\r\n"
"Content-Type: text/plain\r\n"
"Content-Length: 14\r\n" // Always set Content-Length
"\r\n"
"Nothing to do.");
}
}
// Returning non-zero tells mongoose that our function has replied to
// the client, and mongoose should not send client any more data.
return 1;
}
static void *websocket_keepalive_static(void *thread_func_param)
{
web_engine *engine = static_cast<web_engine *>(thread_func_param);
@ -367,6 +386,7 @@ web_engine::web_engine(emu_options &options)
callbacks.begin_request = begin_request_handler_static;
callbacks.websocket_ready = websocket_ready_handler_static;
callbacks.websocket_data = websocket_data_handler_static;
callbacks.http_error = begin_http_error_handler_static;
// Start the web server.
if (m_options.http()) {

View File

@ -31,6 +31,7 @@ public:
void websocket_ready_handler(struct mg_connection *conn);
int websocket_data_handler(struct mg_connection *conn, int flags, char *data, size_t data_len);
int begin_request_handler(struct mg_connection *conn);
int begin_http_error_handler(struct mg_connection *conn, int status);
void *websocket_keepalive();
protected:
// getters