-rw-r--r-- | cgit.c | 4 | ||||
-rw-r--r-- | cgit.h | 1 | ||||
-rw-r--r-- | ui-plain.c | 1 | ||||
-rw-r--r-- | ui-shared.c | 6 |
4 files changed, 12 insertions, 0 deletions
@@ -208,2 +208,3 @@ static void prepare_context(struct cgit_context *ctx) ctx->page.expires = ctx->page.modified; + ctx->page.etag = NULL; } @@ -433,2 +434,3 @@ int main(int argc, const char **argv) const char *cgit_config_env = getenv("CGIT_CONFIG"); + const char *method = getenv("REQUEST_METHOD"); const char *path; @@ -479,2 +481,4 @@ int main(int argc, const char **argv) ctx.page.expires += ttl*60; + if (method && !strcmp(method, "HEAD")) + ctx.cfg.nocache = 1; if (ctx.cfg.nocache) @@ -182,2 +182,3 @@ struct cgit_page { char *filename; + char *etag; char *title; @@ -39,2 +39,3 @@ static void print_object(const unsigned char *sha1, const char *path) ctx.page.size = size; + ctx.page.etag = sha1_to_hex(sha1); cgit_print_http_headers(&ctx); diff --git a/ui-shared.c b/ui-shared.c index 29036d0..10be3c0 100644 --- a/ui-shared.c +++ b/ui-shared.c @@ -469,2 +469,4 @@ void cgit_print_http_headers(struct cgit_context *ctx) { + const char *method = getenv("REQUEST_METHOD"); + if (ctx->page.status) @@ -483,3 +485,7 @@ void cgit_print_http_headers(struct cgit_context *ctx) htmlf("Expires: %s\n", http_date(ctx->page.expires)); + if (ctx->page.etag) + htmlf("ETag: \"%s\"\n", ctx->page.etag); html("\n"); + if (method && !strcmp(method, "HEAD")) + exit(0); } |