file: add support for disabling cache related precondition checks via handlers
authorFelix Fietkau <nbd@nbd.name>
Thu, 16 Jun 2016 16:29:59 +0000 (18:29 +0200)
committerFelix Fietkau <nbd@nbd.name>
Thu, 16 Jun 2016 16:29:59 +0000 (18:29 +0200)
Signed-off-by: Felix Fietkau <nbd@nbd.name>
file.c
handler.c
uhttpd.h

diff --git a/file.c b/file.c
index e801a9ecc29286405944641169bed1ec78fb77ff..2a948186932e49fada921a5c2b7f0de1f801c513 100644 (file)
--- a/file.c
+++ b/file.c
@@ -565,11 +565,12 @@ static void uh_file_free(struct client *cl)
 static void uh_file_data(struct client *cl, struct path_info *pi, int fd)
 {
        /* test preconditions */
-       if (!uh_file_if_modified_since(cl, &pi->stat) ||
-               !uh_file_if_match(cl, &pi->stat) ||
-               !uh_file_if_range(cl, &pi->stat) ||
-               !uh_file_if_unmodified_since(cl, &pi->stat) ||
-               !uh_file_if_none_match(cl, &pi->stat)) {
+       if (!cl->dispatch.no_cache &&
+           (!uh_file_if_modified_since(cl, &pi->stat) ||
+            !uh_file_if_match(cl, &pi->stat) ||
+            !uh_file_if_range(cl, &pi->stat) ||
+            !uh_file_if_unmodified_since(cl, &pi->stat) ||
+            !uh_file_if_none_match(cl, &pi->stat))) {
                ustream_printf(cl->us, "\r\n");
                uh_request_done(cl);
                close(fd);
index 0279a6c1e24228f7e8beed303d84ba8cd89ac686..04e71e0f9ef65f6d99f6d3e82917916fbe2b5616 100644 (file)
--- a/handler.c
+++ b/handler.c
@@ -120,6 +120,14 @@ handle_add_header(struct json_script_ctx *ctx, struct blob_attr *data)
                           blobmsg_get_string(tb[1]));
 }
 
+static void
+handle_no_cache(struct json_script_ctx *ctx, struct blob_attr *data)
+{
+       struct client *cl = cur_client;
+
+       cl->dispatch.no_cache = true;
+}
+
 static void
 handle_command(struct json_script_ctx *ctx, const char *name,
               struct blob_attr *data, struct blob_attr *vars)
@@ -131,6 +139,7 @@ handle_command(struct json_script_ctx *ctx, const char *name,
                { "redirect", handle_redirect },
                { "rewrite", handle_set_uri },
                { "add-header", handle_add_header },
+               { "no-cache", handle_no_cache },
        };
        int i;
 
index b022ecf509ece2579ee9c80aada1f54b44c6f8d3..fe05f0d9284782dbdf1ec600a41f2042c3fa605e 100644 (file)
--- a/uhttpd.h
+++ b/uhttpd.h
@@ -224,6 +224,7 @@ struct dispatch {
        void (*req_free)(struct client *cl);
 
        bool data_blocked;
+       bool no_cache;
 
        union {
                struct {