From: Lars Hjemli Date: Sat, 25 Jul 2009 09:59:22 +0000 (+0200) Subject: Merge branch 'plain-etag' X-Git-Url: https://gitweb.ps.run/ps-cgit/commitdiff_plain/681fdc45473143de3f3c5f69fbc7b94f5d6b0b75?hp=-c Merge branch 'plain-etag' Conflicts: ui-shared.c --- 681fdc45473143de3f3c5f69fbc7b94f5d6b0b75 diff --combined cgit.c index 19adadd,dc1c2e4..ae20257 --- a/cgit.c +++ b/cgit.c @@@ -206,6 -206,7 +206,7 @@@ static void prepare_context(struct cgit ctx->page.size = 0; ctx->page.modified = time(NULL); ctx->page.expires = ctx->page.modified; + ctx->page.etag = NULL; } struct refmatch { @@@ -285,8 -286,6 +286,8 @@@ static int prepare_repo_cmd(struct cgit if (get_sha1(ctx->qry.head, sha1)) { tmp = xstrdup(ctx->qry.head); ctx->qry.head = ctx->repo->defbranch; + ctx->page.status = 404; + ctx->page.statusmsg = "not found"; cgit_print_http_headers(ctx); cgit_print_docstart(ctx); cgit_print_pageheader(ctx); @@@ -431,6 -430,7 +432,7 @@@ static int calc_ttl( 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 -477,8 +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 --combined cgit.h index 00aca4c,2bfbe7b..07a277a --- a/cgit.h +++ b/cgit.h @@@ -180,9 -180,8 +180,10 @@@ struct cgit_page char *mimetype; char *charset; char *filename; + char *etag; char *title; + int status; + char *statusmsg; }; struct cgit_context { diff --combined ui-plain.c index 9a9ae7d,f73cd14..93a3a05 --- a/ui-plain.c +++ b/ui-plain.c @@@ -31,12 -31,10 +31,13 @@@ static void print_object(const unsigne html_status(404, "Not found", 0); return; } - ctx.page.mimetype = "text/plain"; + if (buffer_is_binary(buf, size)) + ctx.page.mimetype = "application/octet-stream"; + 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 --combined ui-shared.c index 29036d0,0dafc83..10be3c0 --- a/ui-shared.c +++ b/ui-shared.c @@@ -34,17 -34,6 +34,17 @@@ void cgit_print_error(char *msg html("\n"); } +char *cgit_httpscheme() +{ + char *https; + + https = getenv("HTTPS"); + if (https != NULL && strcmp(https, "on") == 0) + return "https://"; + else + return "http://"; +} + char *cgit_hosturl() { char *host, *port; @@@ -467,8 -456,8 +467,10 @@@ void cgit_print_age(time_t t, time_t ma 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) htmlf("Content-Type: %s; charset=%s\n", ctx->page.mimetype, ctx->page.charset); @@@ -481,7 -470,11 +483,11 @@@ 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) @@@ -505,8 -498,7 +511,8 @@@ html("'/>\n"); } if (host && ctx->repo) { - html("