Support configuring a function as 404 error handling

Signed-off-by: Jianhui Zhao <jianhuizhao329@gmail.com>
main
Jianhui Zhao 2017-12-30 11:30:33 +08:00
parent f4852fd9cc
commit b8ae313e0a
2 changed files with 7 additions and 1 deletions

View File

@ -122,6 +122,11 @@ static void uh_handle_request(struct uh_client *cl)
if (handle_file_request(cl, path))
return;
if (cl->srv->error404_cb) {
cl->srv->error404_cb(cl);
return;
}
cl->send_error(cl, 404, "Not Found", "The requested PATH %s was not found on this server.", path);
}

View File

@ -30,10 +30,11 @@ struct uh_server {
struct avl_tree actions;
struct list_head clients;
void (*free)(struct uh_server *srv);
void (*set_docroot)(struct uh_server *srv, const char *docroot);
void (*set_index_file)(struct uh_server *srv, const char *index_file);
void (*error404_cb)(struct uh_client *cl);
#if (UHTTPD_SSL_SUPPORT)
int (*ssl_init)(struct uh_server *srv, const char *key, const char *crt);
#endif