URI:
       Return proper error-status when http_send_header() fails - quark - quark web server
  HTML git clone git://git.suckless.org/quark
   DIR Log
   DIR Files
   DIR Refs
   DIR LICENSE
       ---
   DIR commit 68e4ff3021d558e1ff3db1767d1b692cbda70c7c
   DIR parent c0909c70e4767fa47b44b0964cf03e7962e430c3
  HTML Author: Laslo Hunhold <dev@frign.de>
       Date:   Fri, 28 Aug 2020 23:16:47 +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 <dev@frign.de>
       
       Diffstat:
         M http.c                              |       2 +-
         M main.c                              |      16 +++++++++-------
       
       2 files changed, 10 insertions(+), 8 deletions(-)
       ---
   DIR diff --git 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
   DIR diff --git 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 */