From: Lars Hjemli Date: Sat, 25 Jul 2009 10:04:08 +0000 (+0200) Subject: Merge branch 'ml/head-include' X-Git-Url: https://gitweb.ps.run/ps-cgit/commitdiff_plain/542f6a433034935a1aa895f7ef3273968915a5d1?hp=-c Merge branch 'ml/head-include' --- 542f6a433034935a1aa895f7ef3273968915a5d1 diff --combined cgit.c index ae20257,2afc598..513ea12 --- a/cgit.c +++ b/cgit.c @@@ -31,6 -31,8 +31,8 @@@ void config_cb(const char *name, const ctx.cfg.favicon = xstrdup(value); else if (!strcmp(name, "footer")) ctx.cfg.footer = xstrdup(value); + else if (!strcmp(name, "head-include")) + ctx.cfg.head_include = xstrdup(value); else if (!strcmp(name, "header")) ctx.cfg.header = xstrdup(value); else if (!strcmp(name, "logo")) @@@ -206,7 -208,6 +208,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 { @@@ -286,8 -287,6 +288,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); @@@ -432,7 -431,6 +434,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; @@@ -479,8 -477,6 +481,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 07a277a,aed826a..78b30ba --- a/cgit.h +++ b/cgit.h @@@ -136,6 -136,7 +136,7 @@@ struct cgit_config char *css; char *favicon; char *footer; + char *head_include; char *header; char *index_header; char *index_info; @@@ -180,10 -181,7 +181,10 @@@ struct cgit_page char *mimetype; char *charset; char *filename; + char *etag; char *title; + int status; + char *statusmsg; }; struct cgit_context { diff --combined ui-shared.c index 10be3c0,fea2c40..66d5b82 --- 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,10 -456,6 +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); @@@ -483,11 -468,7 +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) @@@ -511,13 -492,14 +511,15 @@@ html("'/>\n"); } if (host && ctx->repo) { - html(""); + html("' type='application/atom+xml'/>\n"); } + if (ctx->cfg.head_include) + html_include(ctx->cfg.head_include); html("\n"); html("\n"); if (ctx->cfg.header)