diff options
author | June McEnroe <june@causal.agency> | 2020-07-10 09:38:46 -0400 |
---|---|---|
committer | June McEnroe <june@causal.agency> | 2020-07-10 09:38:46 -0400 |
commit | bc8b57c001c05f20579b0fdd6c75e26ee6255ffc (patch) | |
tree | 7eba86206c297425e55d8fdf5b7299600b6a9a76 /server.c | |
parent | Add default stylesheet (diff) | |
download | scooper-bc8b57c001c05f20579b0fdd6c75e26ee6255ffc.tar.gz scooper-bc8b57c001c05f20579b0fdd6c75e26ee6255ffc.zip |
Serve stylesheet separately, with caching
Diffstat (limited to 'server.c')
-rw-r--r-- | server.c | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/server.c b/server.c index 751d414..ac8fc4f 100644 --- a/server.c +++ b/server.c @@ -48,6 +48,11 @@ const struct kvalid Keys[KeysLen] = { bool pagePublic; int pageLimit = 100; +static const char CSS[] = { +#include "default.css.h" +}; +static const char *Cache = "public, max-age=86400, immutable"; + static enum kcgi_err request(struct kreq *req) { if (req->method != KMETHOD_HEAD && req->method != KMETHOD_GET) { return httpFail(req, KHTTP_405); @@ -57,7 +62,14 @@ static enum kcgi_err request(struct kreq *req) { case Contexts: return pageContexts(req); case Events: return pageEvents(req); case Search: return pageSearch(req); - default: return httpFail(req, KHTTP_404); + case Stylesheet: { + if (req->mime != KMIME_TEXT_CSS) return httpFail(req, KHTTP_404); + return httpHead(req, KHTTP_200, KMIME_TEXT_CSS) + || khttp_head(req, kresps[KRESP_CACHE_CONTROL], "%s", Cache) + || khttp_body(req) + || khttp_write(req, CSS, sizeof(CSS)); + } + default: return httpFail(req, KHTTP_404); } } |