summaryrefslogtreecommitdiffabout
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--cgit.c4
-rw-r--r--cgit.h1
-rw-r--r--ui-plain.c1
-rw-r--r--ui-shared.c6
4 files changed, 12 insertions, 0 deletions
diff --git a/cgit.c b/cgit.c
index 19adadd..ae20257 100644
--- a/cgit.c
+++ b/cgit.c
@@ -201,16 +201,17 @@ static void prepare_context(struct cgit_context *ctx)
201 ctx->cfg.summary_log = 10; 201 ctx->cfg.summary_log = 10;
202 ctx->cfg.summary_tags = 10; 202 ctx->cfg.summary_tags = 10;
203 ctx->page.mimetype = "text/html"; 203 ctx->page.mimetype = "text/html";
204 ctx->page.charset = PAGE_ENCODING; 204 ctx->page.charset = PAGE_ENCODING;
205 ctx->page.filename = NULL; 205 ctx->page.filename = NULL;
206 ctx->page.size = 0; 206 ctx->page.size = 0;
207 ctx->page.modified = time(NULL); 207 ctx->page.modified = time(NULL);
208 ctx->page.expires = ctx->page.modified; 208 ctx->page.expires = ctx->page.modified;
209 ctx->page.etag = NULL;
209} 210}
210 211
211struct refmatch { 212struct refmatch {
212 char *req_ref; 213 char *req_ref;
213 char *first_ref; 214 char *first_ref;
214 int match; 215 int match;
215}; 216};
216 217
@@ -426,16 +427,17 @@ static int calc_ttl()
426 return ctx.cfg.cache_static_ttl; 427 return ctx.cfg.cache_static_ttl;
427 428
428 return ctx.cfg.cache_repo_ttl; 429 return ctx.cfg.cache_repo_ttl;
429} 430}
430 431
431int main(int argc, const char **argv) 432int main(int argc, const char **argv)
432{ 433{
433 const char *cgit_config_env = getenv("CGIT_CONFIG"); 434 const char *cgit_config_env = getenv("CGIT_CONFIG");
435 const char *method = getenv("REQUEST_METHOD");
434 const char *path; 436 const char *path;
435 char *qry; 437 char *qry;
436 int err, ttl; 438 int err, ttl;
437 439
438 prepare_context(&ctx); 440 prepare_context(&ctx);
439 cgit_repolist.length = 0; 441 cgit_repolist.length = 0;
440 cgit_repolist.count = 0; 442 cgit_repolist.count = 0;
441 cgit_repolist.repos = NULL; 443 cgit_repolist.repos = NULL;
@@ -472,16 +474,18 @@ int main(int argc, const char **argv)
472 free(qry); 474 free(qry);
473 } else 475 } else
474 ctx.qry.raw = ctx.qry.url; 476 ctx.qry.raw = ctx.qry.url;
475 cgit_parse_url(ctx.qry.url); 477 cgit_parse_url(ctx.qry.url);
476 } 478 }
477 479
478 ttl = calc_ttl(); 480 ttl = calc_ttl();
479 ctx.page.expires += ttl*60; 481 ctx.page.expires += ttl*60;
482 if (method && !strcmp(method, "HEAD"))
483 ctx.cfg.nocache = 1;
480 if (ctx.cfg.nocache) 484 if (ctx.cfg.nocache)
481 ctx.cfg.cache_size = 0; 485 ctx.cfg.cache_size = 0;
482 err = cache_process(ctx.cfg.cache_size, ctx.cfg.cache_root, 486 err = cache_process(ctx.cfg.cache_size, ctx.cfg.cache_root,
483 ctx.qry.raw, ttl, process_request, &ctx); 487 ctx.qry.raw, ttl, process_request, &ctx);
484 if (err) 488 if (err)
485 cgit_print_error(fmt("Error processing page: %s (%d)", 489 cgit_print_error(fmt("Error processing page: %s (%d)",
486 strerror(err), err)); 490 strerror(err), err));
487 return err; 491 return err;
diff --git a/cgit.h b/cgit.h
index 00aca4c..07a277a 100644
--- a/cgit.h
+++ b/cgit.h
@@ -175,16 +175,17 @@ struct cgit_config {
175 175
176struct cgit_page { 176struct cgit_page {
177 time_t modified; 177 time_t modified;
178 time_t expires; 178 time_t expires;
179 size_t size; 179 size_t size;
180 char *mimetype; 180 char *mimetype;
181 char *charset; 181 char *charset;
182 char *filename; 182 char *filename;
183 char *etag;
183 char *title; 184 char *title;
184 int status; 185 int status;
185 char *statusmsg; 186 char *statusmsg;
186}; 187};
187 188
188struct cgit_context { 189struct cgit_context {
189 struct cgit_query qry; 190 struct cgit_query qry;
190 struct cgit_config cfg; 191 struct cgit_config cfg;
diff --git a/ui-plain.c b/ui-plain.c
index 9a9ae7d..93a3a05 100644
--- a/ui-plain.c
+++ b/ui-plain.c
@@ -32,16 +32,17 @@ static void print_object(const unsigned char *sha1, const char *path)
32 return; 32 return;
33 } 33 }
34 if (buffer_is_binary(buf, size)) 34 if (buffer_is_binary(buf, size))
35 ctx.page.mimetype = "application/octet-stream"; 35 ctx.page.mimetype = "application/octet-stream";
36 else 36 else
37 ctx.page.mimetype = "text/plain"; 37 ctx.page.mimetype = "text/plain";
38 ctx.page.filename = fmt("%s", path); 38 ctx.page.filename = fmt("%s", path);
39 ctx.page.size = size; 39 ctx.page.size = size;
40 ctx.page.etag = sha1_to_hex(sha1);
40 cgit_print_http_headers(&ctx); 41 cgit_print_http_headers(&ctx);
41 html_raw(buf, size); 42 html_raw(buf, size);
42 match = 1; 43 match = 1;
43} 44}
44 45
45static int walk_tree(const unsigned char *sha1, const char *base, int baselen, 46static int walk_tree(const unsigned char *sha1, const char *base, int baselen,
46 const char *pathname, unsigned mode, int stage, 47 const char *pathname, unsigned mode, int stage,
47 void *cbdata) 48 void *cbdata)
diff --git a/ui-shared.c b/ui-shared.c
index 29036d0..10be3c0 100644
--- a/ui-shared.c
+++ b/ui-shared.c
@@ -462,31 +462,37 @@ void cgit_print_age(time_t t, time_t max_relative, char *format)
462 return; 462 return;
463 } 463 }
464 htmlf("<span class='age-years'>%.0f years</span>", 464 htmlf("<span class='age-years'>%.0f years</span>",
465 secs * 1.0 / TM_YEAR); 465 secs * 1.0 / TM_YEAR);
466} 466}
467 467
468void cgit_print_http_headers(struct cgit_context *ctx) 468void cgit_print_http_headers(struct cgit_context *ctx)
469{ 469{
470 const char *method = getenv("REQUEST_METHOD");
471
470 if (ctx->page.status) 472 if (ctx->page.status)
471 htmlf("Status: %d %s\n", ctx->page.status, ctx->page.statusmsg); 473 htmlf("Status: %d %s\n", ctx->page.status, ctx->page.statusmsg);
472 if (ctx->page.mimetype && ctx->page.charset) 474 if (ctx->page.mimetype && ctx->page.charset)
473 htmlf("Content-Type: %s; charset=%s\n", ctx->page.mimetype, 475 htmlf("Content-Type: %s; charset=%s\n", ctx->page.mimetype,
474 ctx->page.charset); 476 ctx->page.charset);
475 else if (ctx->page.mimetype) 477 else if (ctx->page.mimetype)
476 htmlf("Content-Type: %s\n", ctx->page.mimetype); 478 htmlf("Content-Type: %s\n", ctx->page.mimetype);
477 if (ctx->page.size) 479 if (ctx->page.size)
478 htmlf("Content-Length: %ld\n", ctx->page.size); 480 htmlf("Content-Length: %ld\n", ctx->page.size);
479 if (ctx->page.filename) 481 if (ctx->page.filename)
480 htmlf("Content-Disposition: inline; filename=\"%s\"\n", 482 htmlf("Content-Disposition: inline; filename=\"%s\"\n",
481 ctx->page.filename); 483 ctx->page.filename);
482 htmlf("Last-Modified: %s\n", http_date(ctx->page.modified)); 484 htmlf("Last-Modified: %s\n", http_date(ctx->page.modified));
483 htmlf("Expires: %s\n", http_date(ctx->page.expires)); 485 htmlf("Expires: %s\n", http_date(ctx->page.expires));
486 if (ctx->page.etag)
487 htmlf("ETag: \"%s\"\n", ctx->page.etag);
484 html("\n"); 488 html("\n");
489 if (method && !strcmp(method, "HEAD"))
490 exit(0);
485} 491}
486 492
487void cgit_print_docstart(struct cgit_context *ctx) 493void cgit_print_docstart(struct cgit_context *ctx)
488{ 494{
489 char *host = cgit_hosturl(); 495 char *host = cgit_hosturl();
490 html(cgit_doctype); 496 html(cgit_doctype);
491 html("<html xmlns='http://www.w3.org/1999/xhtml' xml:lang='en' lang='en'>\n"); 497 html("<html xmlns='http://www.w3.org/1999/xhtml' xml:lang='en' lang='en'>\n");
492 html("<head>\n"); 498 html("<head>\n");