diff options
| author | Xavier Del Campo Romero <xavi.dcr@tutanota.com> | 2023-03-09 01:23:02 +0100 |
|---|---|---|
| committer | Xavier Del Campo Romero <xavi.dcr@tutanota.com> | 2023-03-09 01:23:02 +0100 |
| commit | 13f96054f6fb68aae464363e283e32f01d2da1a3 (patch) | |
| tree | ac297e3a8b48eaf123e158aa78604be1b7951ea6 | |
| parent | 8016f537ca5a4bbde6fee2566ff82cd222122915 (diff) | |
| download | slcl-13f96054f6fb68aae464363e283e32f01d2da1a3.tar.gz | |
page.c: Provide meaningful description on HTTP 404
| -rw-r--r-- | page.c | 36 |
1 files changed, 28 insertions, 8 deletions
@@ -837,6 +837,33 @@ static int serve_file(struct http_response *const r, return 0; } +static int page_not_found(struct http_response *const r) +{ + static const char body[] = + DOCTYPE_TAG + "<html>\n" + " <head>" + " " PROJECT_TAG "\n" + " </head>" + "File or directory not found\n" + "</html>"; + + *r = (const struct http_response) + { + .status = HTTP_STATUS_NOT_FOUND, + .buf.ro = body, + .n = sizeof body - 1 + }; + + if (http_response_add_header(r, "Content-Type", "text/html")) + { + fprintf(stderr, "%s: http_response_add_header failed\n", __func__); + return -1; + } + + return 0; +} + int page_resource(struct http_response *const r, const char *const dir, const char *const root, const char *const res, const struct page_quota *const q) @@ -849,14 +876,7 @@ int page_resource(struct http_response *const r, const char *const dir, __func__, res, strerror(errno)); if (errno == ENOENT) - { - *r = (const struct http_response) - { - .status = HTTP_STATUS_NOT_FOUND - }; - - return 0; - } + return page_not_found(r); else return -1; } |
