-rw-r--r-- | cgit.c | 6 | ||||
-rw-r--r-- | cgit.h | 3 | ||||
-rw-r--r-- | ui-atom.c | 6 | ||||
-rw-r--r-- | ui-blob.c | 8 | ||||
-rw-r--r-- | ui-plain.c | 4 | ||||
-rw-r--r-- | ui-shared.c | 22 | ||||
-rw-r--r-- | ui-shared.h | 1 |
7 files changed, 46 insertions, 4 deletions
@@ -210,2 +210,3 @@ static void prepare_context(struct cgit_context *ctx) | |||
210 | ctx->page.expires = ctx->page.modified; | 210 | ctx->page.expires = ctx->page.modified; |
211 | ctx->page.etag = NULL; | ||
211 | } | 212 | } |
@@ -289,2 +290,4 @@ static int prepare_repo_cmd(struct cgit_context *ctx) | |||
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); |
@@ -433,2 +436,3 @@ int main(int argc, const char **argv) | |||
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; |
@@ -479,2 +483,4 @@ int main(int argc, const char **argv) | |||
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) |
@@ -183,3 +183,6 @@ struct cgit_page { | |||
183 | char *filename; | 183 | char *filename; |
184 | char *etag; | ||
184 | char *title; | 185 | char *title; |
186 | int status; | ||
187 | char *statusmsg; | ||
185 | }; | 188 | }; |
@@ -54,3 +54,4 @@ void add_entry(struct commit *commit, char *host) | |||
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); |
@@ -115,3 +116,4 @@ void cgit_print_atom(char *tip, char *path, int max_count) | |||
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); |
@@ -29,3 +29,3 @@ void cgit_print_blob(const char *hex, char *path, const char *head) | |||
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; |
@@ -69,2 +69,8 @@ void cgit_print_blob(const char *hex, char *path, const char *head) | |||
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; |
@@ -33,2 +33,5 @@ static void print_object(const unsigned char *sha1, const char *path) | |||
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"; |
@@ -36,2 +39,3 @@ static void print_object(const unsigned char *sha1, const char *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); |
diff --git a/ui-shared.c b/ui-shared.c index fea2c40..66d5b82 100644 --- a/ui-shared.c +++ b/ui-shared.c | |||
@@ -36,2 +36,13 @@ void cgit_print_error(char *msg) | |||
36 | 36 | ||
37 | char *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 | |||
37 | char *cgit_hosturl() | 48 | char *cgit_hosturl() |
@@ -458,2 +469,6 @@ void 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) |
@@ -470,3 +485,7 @@ void cgit_print_http_headers(struct cgit_context *ctx) | |||
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 | } |
@@ -494,3 +513,4 @@ void cgit_print_docstart(struct cgit_context *ctx) | |||
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()); |
diff --git a/ui-shared.h b/ui-shared.h index 5a3821f..bff4826 100644 --- a/ui-shared.h +++ b/ui-shared.h | |||
@@ -3,2 +3,3 @@ | |||
3 | 3 | ||
4 | extern char *cgit_httpscheme(); | ||
4 | extern char *cgit_hosturl(); | 5 | extern char *cgit_hosturl(); |