]> git.cameronkatri.com Git - cgit.git/commitdiff
Add support for ETag in 'plain' view
authorLars Hjemli <hjemli@gmail.com>
Thu, 19 Feb 2009 21:38:36 +0000 (22:38 +0100)
committerLars Hjemli <hjemli@gmail.com>
Thu, 19 Feb 2009 21:38:36 +0000 (22:38 +0100)
When downloading a blob identified by its path, the client might want
to know if the blob has been modified since a previous download of the
same path. To this end, an ETag containing the blob SHA1 seems to be
ideal.

Todo: add support for HEAD requests...

Suggested-by: Owen Taylor <otaylor@redhat.com>
Signed-off-by: Lars Hjemli <hjemli@gmail.com>
cgit.c
cgit.h
ui-plain.c
ui-shared.c

diff --git a/cgit.c b/cgit.c
index 64d95f9a3a7bb56197988e6730c4576173811db0..411e42132be546f3b8a9fc2c86b3f2f1dd04e04e 100644 (file)
--- a/cgit.c
+++ b/cgit.c
@@ -206,6 +206,7 @@ static void prepare_context(struct cgit_context *ctx)
        ctx->page.size = 0;
        ctx->page.modified = time(NULL);
        ctx->page.expires = ctx->page.modified;
+       ctx->page.etag = NULL;
 }
 
 struct refmatch {
diff --git a/cgit.h b/cgit.h
index 5f7af51a68e0a773cac9c2758df51d5f0af90ff6..2bfbe7b0007ae65939cf972bd9cd3eb3093fef48 100644 (file)
--- a/cgit.h
+++ b/cgit.h
@@ -180,6 +180,7 @@ struct cgit_page {
        char *mimetype;
        char *charset;
        char *filename;
+       char *etag;
        char *title;
 };
 
index 5addd9e686539ca41f264394ecf6836aa739af4e..f73cd14e8e56e3b080fe73a647c5ff91ed2f58ed 100644 (file)
@@ -34,6 +34,7 @@ static void print_object(const unsigned char *sha1, const char *path)
        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;
index de77bbfadf86dd08e794145395ca1e20e1f63e9c..86a7d29cbc7263c2614229ed7909790eacb884a8 100644 (file)
@@ -468,6 +468,8 @@ void cgit_print_http_headers(struct cgit_context *ctx)
                      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");
 }