summaryrefslogtreecommitdiffabout
Unidiff
Diffstat (more/less context) (show whitespace changes)
-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.c4
-rw-r--r--ui-shared.c22
-rw-r--r--ui-shared.h1
7 files changed, 46 insertions, 4 deletions
diff --git a/cgit.c b/cgit.c
index 2afc598..513ea12 100644
--- a/cgit.c
+++ b/cgit.c
@@ -209,4 +209,5 @@ static void prepare_context(struct cgit_context *ctx)
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
@@ -288,4 +289,6 @@ static int prepare_repo_cmd(struct cgit_context *ctx)
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);
@@ -432,4 +435,5 @@ int 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;
@@ -478,4 +482,6 @@ int main(int argc, const char **argv)
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;
diff --git a/cgit.h b/cgit.h
index aed826a..78b30ba 100644
--- a/cgit.h
+++ b/cgit.h
@@ -182,5 +182,8 @@ struct cgit_page {
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
diff --git a/ui-atom.c b/ui-atom.c
index a6ea3ee..e5c31d9 100644
--- a/ui-atom.c
+++ b/ui-atom.c
@@ -53,5 +53,6 @@ void add_entry(struct commit *commit, char *host)
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));
@@ -114,5 +115,6 @@ void cgit_print_atom(char *tip, char *path, int max_count)
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));
diff --git a/ui-blob.c b/ui-blob.c
index 3cda03d..2ccd31d 100644
--- a/ui-blob.c
+++ b/ui-blob.c
@@ -28,5 +28,5 @@ void cgit_print_blob(const char *hex, char *path, const char *head)
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;
@@ -68,4 +68,10 @@ void cgit_print_blob(const char *hex, char *path, const char *head)
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);
diff --git a/ui-plain.c b/ui-plain.c
index 5addd9e..93a3a05 100644
--- a/ui-plain.c
+++ b/ui-plain.c
@@ -32,7 +32,11 @@ static void print_object(const unsigned char *sha1, const char *path)
32 return; 32 return;
33 } 33 }
34 if (buffer_is_binary(buf, size))
35 ctx.page.mimetype = "application/octet-stream";
36 else
34 ctx.page.mimetype = "text/plain"; 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);
diff --git a/ui-shared.c b/ui-shared.c
index fea2c40..66d5b82 100644
--- a/ui-shared.c
+++ b/ui-shared.c
@@ -35,4 +35,15 @@ void cgit_print_error(char *msg)
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{
@@ -457,4 +468,8 @@ void cgit_print_age(time_t t, time_t max_relative, char *format)
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,
@@ -469,5 +484,9 @@ void cgit_print_http_headers(struct cgit_context *ctx)
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
@@ -493,5 +512,6 @@ void cgit_print_docstart(struct cgit_context *ctx)
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,
diff --git a/ui-shared.h b/ui-shared.h
index 5a3821f..bff4826 100644
--- a/ui-shared.h
+++ b/ui-shared.h
@@ -2,4 +2,5 @@
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);