fix redirect status
[project/uhttpd.git] / file.c
diff --git a/file.c b/file.c
index 5de96f8250245c5c297c41cce9183da535996889..22bdfb83f29ab017092757107774c6d28611d453 100644 (file)
--- a/file.c
+++ b/file.c
@@ -176,6 +176,13 @@ uh_path_lookup(struct client *cl, const char *url)
                exists = !!canonpath(uh_buf, path_phys);
                uh_buf[i] = ch;
 
+               if (!exists)
+                       continue;
+
+               /* test current path */
+               if (stat(path_phys, &p.stat))
+                       continue;
+
                snprintf(path_info, sizeof(path_info), "%s", uh_buf + i);
                break;
        }
@@ -186,10 +193,6 @@ uh_path_lookup(struct client *cl, const char *url)
             path_phys[docroot_len] != '/'))
                return NULL;
 
-       /* test current path */
-       if (stat(path_phys, &p.stat))
-               return NULL;
-
        /* is a regular file */
        if (p.stat.st_mode & S_IFREG) {
                p.root = docroot;
@@ -683,10 +686,12 @@ static bool __handle_file_request(struct client *cl, char *url)
 
 void uh_handle_request(struct client *cl)
 {
+       struct http_request *req = &cl->request;
        struct dispatch_handler *d;
        char *url = blobmsg_data(blob_data(cl->hdr.head));;
        char *error_handler;
 
+       req->redirect_status = 200;
        d = dispatch_find(url, NULL);
        if (d) {
                d->handle_request(cl, url, NULL);
@@ -696,10 +701,13 @@ void uh_handle_request(struct client *cl)
        if (__handle_file_request(cl, url))
                return;
 
-       error_handler = alloca(strlen(conf.error_handler) + 1);
-       strcpy(error_handler, conf.error_handler);
-       if (__handle_file_request(cl, error_handler))
-               return;
+       req->redirect_status = 404;
+       if (conf.error_handler) {
+               error_handler = alloca(strlen(conf.error_handler) + 1);
+               strcpy(error_handler, conf.error_handler);
+               if (__handle_file_request(cl, error_handler))
+                       return;
+       }
 
        uh_client_error(cl, 404, "Not Found", "The requested URL %s was not found on this server.", url);
 }