From 68e4ff3021d558e1ff3db1767d1b692cbda70c7c Mon Sep 17 00:00:00 2001 From: Laslo Hunhold Date: Fri, 28 Aug 2020 23:16:47 +0200 Subject: [PATCH] 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 --- http.c | 2 +- main.c | 16 +++++++++------- 2 files changed, 10 insertions(+), 8 deletions(-) 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 */