quark

quark web server
git clone git://git.suckless.org/quark
Log | Files | Refs | LICENSE

commit 68e4ff3021d558e1ff3db1767d1b692cbda70c7c
parent c0909c70e4767fa47b44b0964cf03e7962e430c3
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:
Mhttp.c | 2+-
Mmain.c | 16+++++++++-------
2 files changed, 10 insertions(+), 8 deletions(-)

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 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 */