aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--cgit.c6
-rw-r--r--cgit.h3
-rw-r--r--ui-atom.c6
-rw-r--r--ui-blob.c8
-rw-r--r--ui-plain.c6
-rw-r--r--ui-shared.c22
-rw-r--r--ui-shared.h1
7 files changed, 47 insertions, 5 deletions
diff --git a/cgit.c b/cgit.c
index 2afc598..513ea12 100644
--- a/cgit.c
+++ b/cgit.c
@@ -208,6 +208,7 @@ static void prepare_context(struct cgit_context *ctx)
208 ctx->page.size = 0; 208 ctx->page.size = 0;
209 ctx->page.modified = time(NULL); 209 ctx->page.modified = time(NULL);
210 ctx->page.expires = ctx->page.modified; 210 ctx->page.expires = ctx->page.modified;
211 ctx->page.etag = NULL;
211} 212}
212 213
213struct refmatch { 214struct refmatch {
@@ -287,6 +288,8 @@ static int prepare_repo_cmd(struct cgit_context *ctx)
287 if (get_sha1(ctx->qry.head, sha1)) { 288 if (get_sha1(ctx->qry.head, sha1)) {
288 tmp = xstrdup(ctx->qry.head); 289 tmp = xstrdup(ctx->qry.head);
289 ctx->qry.head = ctx->repo->defbranch; 290 ctx->qry.head = ctx->repo->defbranch;
291 ctx->page.status = 404;
292 ctx->page.statusmsg = "not found";
290 cgit_print_http_headers(ctx); 293 cgit_print_http_headers(ctx);
291 cgit_print_docstart(ctx); 294 cgit_print_docstart(ctx);
292 cgit_print_pageheader(ctx); 295 cgit_print_pageheader(ctx);
@@ -431,6 +434,7 @@ static int calc_ttl()
431int main(int argc, const char **argv) 434int main(int argc, const char **argv)
432{ 435{
433 const char *cgit_config_env = getenv("CGIT_CONFIG"); 436 const char *cgit_config_env = getenv("CGIT_CONFIG");
437 const char *method = getenv("REQUEST_METHOD");
434 const char *path; 438 const char *path;
435 char *qry; 439 char *qry;
436 int err, ttl; 440 int err, ttl;
@@ -477,6 +481,8 @@ int main(int argc, const char **argv)
477 481
478 ttl = calc_ttl(); 482 ttl = calc_ttl();
479 ctx.page.expires += ttl*60; 483 ctx.page.expires += ttl*60;
484 if (method && !strcmp(method, "HEAD"))
485 ctx.cfg.nocache = 1;
480 if (ctx.cfg.nocache) 486 if (ctx.cfg.nocache)
481 ctx.cfg.cache_size = 0; 487 ctx.cfg.cache_size = 0;
482 err = cache_process(ctx.cfg.cache_size, ctx.cfg.cache_root, 488 err = cache_process(ctx.cfg.cache_size, ctx.cfg.cache_root,
diff --git a/cgit.h b/cgit.h
index aed826a..78b30ba 100644
--- a/cgit.h
+++ b/cgit.h
@@ -181,7 +181,10 @@ struct cgit_page {
181 char *mimetype; 181 char *mimetype;
182 char *charset; 182 char *charset;
183 char *filename; 183 char *filename;
184 char *etag;
184 char *title; 185 char *title;
186 int status;
187 char *statusmsg;
185}; 188};
186 189
187struct cgit_context { 190struct cgit_context {
diff --git a/ui-atom.c b/ui-atom.c
index a6ea3ee..e5c31d9 100644
--- a/ui-atom.c
+++ b/ui-atom.c
@@ -52,7 +52,8 @@ void add_entry(struct commit *commit, char *host)
52 cgit_print_date(info->author_date, FMT_ATOMDATE, ctx.cfg.local_time); 52 cgit_print_date(info->author_date, FMT_ATOMDATE, ctx.cfg.local_time);
53 html("</published>\n"); 53 html("</published>\n");
54 if (host) { 54 if (host) {
55 html("<link rel='alternate' type='text/html' href='http://"); 55 html("<link rel='alternate' type='text/html' href='");
56 html(cgit_httpscheme());
56 html_attr(host); 57 html_attr(host);
57 html_attr(cgit_pageurl(ctx.repo->url, "commit", NULL)); 58 html_attr(cgit_pageurl(ctx.repo->url, "commit", NULL));
58 if (ctx.cfg.virtual_root) 59 if (ctx.cfg.virtual_root)
@@ -113,7 +114,8 @@ void cgit_print_atom(char *tip, char *path, int max_count)
113 html_txt(ctx.repo->desc); 114 html_txt(ctx.repo->desc);
114 html("</subtitle>\n"); 115 html("</subtitle>\n");
115 if (host) { 116 if (host) {
116 html("<link rel='alternate' type='text/html' href='http://"); 117 html("<link rel='alternate' type='text/html' href='");
118 html(cgit_httpscheme());
117 html_attr(host); 119 html_attr(host);
118 html_attr(cgit_repourl(ctx.repo->url)); 120 html_attr(cgit_repourl(ctx.repo->url));
119 html("'/>\n"); 121 html("'/>\n");
diff --git a/ui-blob.c b/ui-blob.c
index 3cda03d..2ccd31d 100644
--- a/ui-blob.c
+++ b/ui-blob.c
@@ -27,7 +27,7 @@ void cgit_print_blob(const char *hex, char *path, const char *head)
27 27
28 unsigned char sha1[20]; 28 unsigned char sha1[20];
29 enum object_type type; 29 enum object_type type;
30 unsigned char *buf; 30 char *buf;
31 unsigned long size; 31 unsigned long size;
32 struct commit *commit; 32 struct commit *commit;
33 const char *paths[] = {path, NULL}; 33 const char *paths[] = {path, NULL};
@@ -67,6 +67,12 @@ void cgit_print_blob(const char *hex, char *path, const char *head)
67 67
68 buf[size] = '\0'; 68 buf[size] = '\0';
69 ctx.page.mimetype = ctx.qry.mimetype; 69 ctx.page.mimetype = ctx.qry.mimetype;
70 if (!ctx.page.mimetype) {
71 if (buffer_is_binary(buf, size))
72 ctx.page.mimetype = "application/octet-stream";
73 else
74 ctx.page.mimetype = "text/plain";
75 }
70 ctx.page.filename = path; 76 ctx.page.filename = path;
71 cgit_print_http_headers(&ctx); 77 cgit_print_http_headers(&ctx);
72 write(htmlfd, buf, size); 78 write(htmlfd, buf, size);
diff --git a/ui-plain.c b/ui-plain.c
index 5addd9e..93a3a05 100644
--- a/ui-plain.c
+++ b/ui-plain.c
@@ -31,9 +31,13 @@ static void print_object(const unsigned char *sha1, const char *path)
31 html_status(404, "Not found", 0); 31 html_status(404, "Not found", 0);
32 return; 32 return;
33 } 33 }
34 ctx.page.mimetype = "text/plain"; 34 if (buffer_is_binary(buf, size))
35 ctx.page.mimetype = "application/octet-stream";
36 else
37 ctx.page.mimetype = "text/plain";
35 ctx.page.filename = fmt("%s", path); 38 ctx.page.filename = fmt("%s", path);
36 ctx.page.size = size; 39 ctx.page.size = size;
40 ctx.page.etag = sha1_to_hex(sha1);
37 cgit_print_http_headers(&ctx); 41 cgit_print_http_headers(&ctx);
38 html_raw(buf, size); 42 html_raw(buf, size);
39 match = 1; 43 match = 1;
diff --git a/ui-shared.c b/ui-shared.c
index fea2c40..66d5b82 100644
--- a/ui-shared.c
+++ b/ui-shared.c
@@ -34,6 +34,17 @@ void cgit_print_error(char *msg)
34 html("</div>\n"); 34 html("</div>\n");
35} 35}
36 36
37char *cgit_httpscheme()
38{
39 char *https;
40
41 https = getenv("HTTPS");
42 if (https != NULL && strcmp(https, "on") == 0)
43 return "https://";
44 else
45 return "http://";
46}
47
37char *cgit_hosturl() 48char *cgit_hosturl()
38{ 49{
39 char *host, *port; 50 char *host, *port;
@@ -456,6 +467,10 @@ void cgit_print_age(time_t t, time_t max_relative, char *format)
456 467
457void cgit_print_http_headers(struct cgit_context *ctx) 468void cgit_print_http_headers(struct cgit_context *ctx)
458{ 469{
470 const char *method = getenv("REQUEST_METHOD");
471
472 if (ctx->page.status)
473 htmlf("Status: %d %s\n", ctx->page.status, ctx->page.statusmsg);
459 if (ctx->page.mimetype && ctx->page.charset) 474 if (ctx->page.mimetype && ctx->page.charset)
460 htmlf("Content-Type: %s; charset=%s\n", ctx->page.mimetype, 475 htmlf("Content-Type: %s; charset=%s\n", ctx->page.mimetype,
461 ctx->page.charset); 476 ctx->page.charset);
@@ -468,7 +483,11 @@ void cgit_print_http_headers(struct cgit_context *ctx)
468 ctx->page.filename); 483 ctx->page.filename);
469 htmlf("Last-Modified: %s\n", http_date(ctx->page.modified)); 484 htmlf("Last-Modified: %s\n", http_date(ctx->page.modified));
470 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);
471 html("\n"); 488 html("\n");
489 if (method && !strcmp(method, "HEAD"))
490 exit(0);
472} 491}
473 492
474void cgit_print_docstart(struct cgit_context *ctx) 493void cgit_print_docstart(struct cgit_context *ctx)
@@ -492,7 +511,8 @@ void cgit_print_docstart(struct cgit_context *ctx)
492 html("'/>\n"); 511 html("'/>\n");
493 } 512 }
494 if (host && ctx->repo) { 513 if (host && ctx->repo) {
495 html("<link rel='alternate' title='Atom feed' href='http://"); 514 html("<link rel='alternate' title='Atom feed' href='");
515 html(cgit_httpscheme());
496 html_attr(cgit_hosturl()); 516 html_attr(cgit_hosturl());
497 html_attr(cgit_fileurl(ctx->repo->url, "atom", ctx->qry.path, 517 html_attr(cgit_fileurl(ctx->repo->url, "atom", ctx->qry.path,
498 fmt("h=%s", ctx->qry.head))); 518 fmt("h=%s", ctx->qry.head)));
diff --git a/ui-shared.h b/ui-shared.h
index 5a3821f..bff4826 100644
--- a/ui-shared.h
+++ b/ui-shared.h
@@ -1,6 +1,7 @@
1#ifndef UI_SHARED_H 1#ifndef UI_SHARED_H
2#define UI_SHARED_H 2#define UI_SHARED_H
3 3
4extern char *cgit_httpscheme();
4extern char *cgit_hosturl(); 5extern char *cgit_hosturl();
5extern char *cgit_repourl(const char *reponame); 6extern char *cgit_repourl(const char *reponame);
6extern char *cgit_fileurl(const char *reponame, const char *pagename, 7extern char *cgit_fileurl(const char *reponame, const char *pagename,