cgit

commit 681fdc45473143de3f3c5f69fbc7b94f5d6b0b75

Author: Lars Hjemli <hjemli@gmail.com>

Merge branch 'plain-etag'

Conflicts:
	ui-shared.c

 cgit.c | 4 ++++
 cgit.h | 1 +
 ui-plain.c | 1 +
 ui-shared.c | 6 ++++++


diff --git a/cgit.c b/cgit.c
index 19adadd2e3a9277aa25916eb1747ee3cbae63f75..ae2025709a05b4f888e9fc090005c5a1a9ed10be 100644
--- a/cgit.c
+++ b/cgit.c
@@ -206,6 +206,7 @@ 	ctx->page.filename = NULL;
 	ctx->page.size = 0;
 	ctx->page.modified = time(NULL);
 	ctx->page.expires = ctx->page.modified;
+	ctx->page.etag = NULL;
 }
 
 struct refmatch {
@@ -431,6 +432,7 @@
 int main(int argc, const char **argv)
 {
 	const char *cgit_config_env = getenv("CGIT_CONFIG");
+	const char *method = getenv("REQUEST_METHOD");
 	const char *path;
 	char *qry;
 	int err, ttl;
@@ -477,6 +479,8 @@ 	}
 
 	ttl = calc_ttl();
 	ctx.page.expires += ttl*60;
+	if (method && !strcmp(method, "HEAD"))
+		ctx.cfg.nocache = 1;
 	if (ctx.cfg.nocache)
 		ctx.cfg.cache_size = 0;
 	err = cache_process(ctx.cfg.cache_size, ctx.cfg.cache_root,




diff --git a/cgit.h b/cgit.h
index 00aca4c36a46d6dc8737b32ea794c917dcfc825e..07a277a3e727b93b64623d4fa366ac3131486bdd 100644
--- a/cgit.h
+++ b/cgit.h
@@ -180,6 +180,7 @@ 	size_t size;
 	char *mimetype;
 	char *charset;
 	char *filename;
+	char *etag;
 	char *title;
 	int status;
 	char *statusmsg;




diff --git a/ui-plain.c b/ui-plain.c
index 9a9ae7d5a80ccea3db7bea37a69405ca60e56edd..93a3a05ac50f7a43b3c50529a011f0c9fdbf547c 100644
--- a/ui-plain.c
+++ b/ui-plain.c
@@ -37,6 +37,7 @@ 	else
 		ctx.page.mimetype = "text/plain";
 	ctx.page.filename = fmt("%s", path);
 	ctx.page.size = size;
+	ctx.page.etag = sha1_to_hex(sha1);
 	cgit_print_http_headers(&ctx);
 	html_raw(buf, size);
 	match = 1;




diff --git a/ui-shared.c b/ui-shared.c
index 29036d0a92ba45643e7db53af2671113fcbff7be..10be3c057dab494ad9782220374d0df258247cf0 100644
--- a/ui-shared.c
+++ b/ui-shared.c
@@ -467,6 +467,8 @@ }
 
 void cgit_print_http_headers(struct cgit_context *ctx)
 {
+	const char *method = getenv("REQUEST_METHOD");
+
 	if (ctx->page.status)
 		htmlf("Status: %d %s\n", ctx->page.status, ctx->page.statusmsg);
 	if (ctx->page.mimetype && ctx->page.charset)
@@ -481,7 +483,11 @@ 		htmlf("Content-Disposition: inline; filename=\"%s\"\n",
 		      ctx->page.filename);
 	htmlf("Last-Modified: %s\n", http_date(ctx->page.modified));
 	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);
 }
 
 void cgit_print_docstart(struct cgit_context *ctx)