aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorXavier Del Campo Romero <xavi.dcr@tutanota.com>2023-03-09 01:23:02 +0100
committerXavier Del Campo Romero <xavi.dcr@tutanota.com>2023-03-09 01:23:02 +0100
commit13f96054f6fb68aae464363e283e32f01d2da1a3 (patch)
treeac297e3a8b48eaf123e158aa78604be1b7951ea6
parent8016f537ca5a4bbde6fee2566ff82cd222122915 (diff)
downloadslcl-13f96054f6fb68aae464363e283e32f01d2da1a3.tar.gz
page.c: Provide meaningful description on HTTP 404
-rw-r--r--page.c36
1 files changed, 28 insertions, 8 deletions
diff --git a/page.c b/page.c
index 03671d6..9130147 100644
--- a/page.c
+++ b/page.c
@@ -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;
}