aboutsummaryrefslogtreecommitdiff
path: root/page.c
diff options
context:
space:
mode:
authorXavier Del Campo Romero <xavi.dcr@tutanota.com>2023-10-03 00:09:37 +0200
committerXavier Del Campo Romero <xavi.dcr@tutanota.com>2023-10-14 01:08:02 +0200
commit472b4ddbf151b44f5fc01c4c1752ce5529a0cf85 (patch)
tree623d22494bda1018e9471052603a545eb55b7572 /page.c
parent1d2ce3f9c235f0b6524bbedad0b2ff0abb838888 (diff)
downloadslcl-472b4ddbf151b44f5fc01c4c1752ce5529a0cf85.tar.gz
Implement HEAD support
Diffstat (limited to 'page.c')
-rw-r--r--page.c33
1 files changed, 33 insertions, 0 deletions
diff --git a/page.c b/page.c
index f3856a9..02049a3 100644
--- a/page.c
+++ b/page.c
@@ -2199,3 +2199,36 @@ end:
return ret;
}
+
+int page_head_resource(struct http_response *const r, const char *const res)
+{
+ struct stat sb;
+
+ if (stat(res, &sb))
+ {
+ if (errno == ENOENT || errno == ENOTDIR)
+ return page_not_found(r);
+ else
+ {
+ fprintf(stderr, "%s: stat(2) %s: %s\n",
+ __func__, res, strerror(errno));
+ return -1;
+ }
+ }
+
+ const mode_t m = sb.st_mode;
+
+ if (!S_ISDIR(m) && !S_ISREG(m))
+ {
+ fprintf(stderr, "%s: unexpected st_mode %jd\n", __func__, (intmax_t)m);
+ return -1;
+ }
+
+ *r = (const struct http_response)
+ {
+ .status = HTTP_STATUS_OK,
+ .n = sb.st_size
+ };
+
+ return 0;
+}