commit 68e4ff3021d558e1ff3db1767d1b692cbda70c7c
Author:     Laslo Hunhold <[email protected]>
AuthorDate: Fri Aug 28 23:16:47 2020 +0200
Commit:     Laslo Hunhold <[email protected]>
CommitDate: Fri Aug 28 23:16:47 2020 +0200

    Return proper error-status when http_send_header() fails
    
    Explicitly show that we set the status of the response struct to the
    returned error status. This makes it clear that we are beyond the point
    where the "form" of the response struct matters and it's now only about
    the log-output.
    
    Signed-off-by: Laslo Hunhold <[email protected]>

diff --git a/http.c b/http.c
index 633c2f9..ee075e4 100644
--- a/http.c
+++ b/http.c
@@ -110,7 +110,7 @@ http_send_header(int fd, const struct response *res)
                }
        }
 
-       return res->status;
+       return 0;
 }
 
 static void
diff --git a/main.c b/main.c
index 590e558..deb273b 100644
--- a/main.c
+++ b/main.c
@@ -45,13 +45,15 @@ serve(int infd, const struct sockaddr_storage *in_sa, const 
struct server *srv)
                http_prepare_response(&c.req, &c.res, srv);
        }
 
-       status = http_send_header(c.fd, &c.res);
-
-       /* send data */
-       if (c.res.type == RESTYPE_FILE) {
-               resp_file(c.fd, &c.res);
-       } else if (c.res.type == RESTYPE_DIRLISTING) {
-               resp_dir(c.fd, &c.res);
+       if ((status = http_send_header(c.fd, &c.res))) {
+               c.res.status = status;
+       } else {
+               /* send data */
+               if (c.res.type == RESTYPE_FILE) {
+                       resp_file(c.fd, &c.res);
+               } else if (c.res.type == RESTYPE_DIRLISTING) {
+                       resp_dir(c.fd, &c.res);
+               }
        }
 
        /* write output to log */

Reply via email to