From b8ae313e0acad67195f28f5dd6522df332fe4b1b Mon Sep 17 00:00:00 2001 From: Jianhui Zhao Date: Sat, 30 Dec 2017 11:30:33 +0800 Subject: [PATCH] Support configuring a function as 404 error handling Signed-off-by: Jianhui Zhao --- src/client.c | 5 +++++ src/uhttpd.h | 3 ++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/client.c b/src/client.c index e2b4e6d..22ea3de 100755 --- a/src/client.c +++ b/src/client.c @@ -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); } diff --git a/src/uhttpd.h b/src/uhttpd.h index 836f33a..2844fdb 100755 --- a/src/uhttpd.h +++ b/src/uhttpd.h @@ -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