diff options
author | Felix Fietkau <nbd@openwrt.org> | 2015-11-08 11:41:42 +0100 |
---|---|---|
committer | Felix Fietkau <nbd@openwrt.org> | 2015-11-08 11:45:29 +0100 |
commit | 25023c796a9a55cd7ec7ff364cd1229fab958679 (patch) | |
tree | 74e2f8fcd78e0a0d35a79dbd32781fb82531b9f4 /file.c | |
parent | d9513e62bf484eea8a9ca63c2bfac10f4bdb6c9f (diff) |
add support for handling redirects via a script
In a json_script file you can specify rules for rewriting the URL or
redirecting the browser either unconditionally, or as a fallback where
it would otherwise print a 404 error
Signed-off-by: Felix Fietkau <nbd@openwrt.org>
Diffstat (limited to 'file.c')
-rw-r--r-- | file.c | 10 |
1 files changed, 9 insertions, 1 deletions
@@ -127,7 +127,7 @@ next: /* Returns NULL on error. ** NB: improperly encoded URL should give client 400 [Bad Syntax]; returning ** NULL here causes 404 [Not Found], but that's not too unreasonable. */ -static struct path_info * +struct path_info * uh_path_lookup(struct client *cl, const char *url) { static char path_phys[PATH_MAX]; @@ -864,6 +864,10 @@ void uh_handle_request(struct client *cl) url = uh_handle_alias(url); + uh_handler_run(cl, &url, false); + if (!url) + return; + req->redirect_status = 200; d = dispatch_find(url, NULL); if (d) @@ -872,6 +876,10 @@ void uh_handle_request(struct client *cl) if (__handle_file_request(cl, url)) return; + if (uh_handler_run(cl, &url, true) && + (!url || __handle_file_request(cl, url))) + return; + req->redirect_status = 404; if (conf.error_handler) { error_handler = alloca(strlen(conf.error_handler) + 1); |