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>
This commit is contained in:
Laslo Hunhold 2020-08-28 23:16:47 +02:00
parent c0909c70e4
commit 68e4ff3021
No known key found for this signature in database
GPG key ID: 69576BD24CFCB980
2 changed files with 10 additions and 8 deletions

2
http.c
View file

@ -110,7 +110,7 @@ http_send_header(int fd, const struct response *res)
} }
} }
return res->status; return 0;
} }
static void static void

6
main.c
View file

@ -45,14 +45,16 @@ serve(int infd, const struct sockaddr_storage *in_sa, const struct server *srv)
http_prepare_response(&c.req, &c.res, srv); http_prepare_response(&c.req, &c.res, srv);
} }
status = http_send_header(c.fd, &c.res); if ((status = http_send_header(c.fd, &c.res))) {
c.res.status = status;
} else {
/* send data */ /* send data */
if (c.res.type == RESTYPE_FILE) { if (c.res.type == RESTYPE_FILE) {
resp_file(c.fd, &c.res); resp_file(c.fd, &c.res);
} else if (c.res.type == RESTYPE_DIRLISTING) { } else if (c.res.type == RESTYPE_DIRLISTING) {
resp_dir(c.fd, &c.res); resp_dir(c.fd, &c.res);
} }
}
/* write output to log */ /* write output to log */
t = time(NULL); t = time(NULL);