summaryrefslogtreecommitdiffabout
Side-by-side diff
Diffstat (more/less context) (ignore 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.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
@@ -210,2 +210,3 @@ static void prepare_context(struct cgit_context *ctx)
ctx->page.expires = ctx->page.modified;
+ ctx->page.etag = NULL;
}
@@ -289,2 +290,4 @@ static int prepare_repo_cmd(struct cgit_context *ctx)
ctx->qry.head = ctx->repo->defbranch;
+ ctx->page.status = 404;
+ ctx->page.statusmsg = "not found";
cgit_print_http_headers(ctx);
@@ -433,2 +436,3 @@ int main(int argc, const char **argv)
const char *cgit_config_env = getenv("CGIT_CONFIG");
+ const char *method = getenv("REQUEST_METHOD");
const char *path;
@@ -479,2 +483,4 @@ int main(int argc, const char **argv)
ctx.page.expires += ttl*60;
+ if (method && !strcmp(method, "HEAD"))
+ ctx.cfg.nocache = 1;
if (ctx.cfg.nocache)
diff --git a/cgit.h b/cgit.h
index aed826a..78b30ba 100644
--- a/cgit.h
+++ b/cgit.h
@@ -183,3 +183,6 @@ struct cgit_page {
char *filename;
+ char *etag;
char *title;
+ int status;
+ char *statusmsg;
};
diff --git a/ui-atom.c b/ui-atom.c
index a6ea3ee..e5c31d9 100644
--- a/ui-atom.c
+++ b/ui-atom.c
@@ -54,3 +54,4 @@ void add_entry(struct commit *commit, char *host)
if (host) {
- html("<link rel='alternate' type='text/html' href='http://");
+ html("<link rel='alternate' type='text/html' href='");
+ html(cgit_httpscheme());
html_attr(host);
@@ -115,3 +116,4 @@ void cgit_print_atom(char *tip, char *path, int max_count)
if (host) {
- html("<link rel='alternate' type='text/html' href='http://");
+ html("<link rel='alternate' type='text/html' href='");
+ html(cgit_httpscheme());
html_attr(host);
diff --git a/ui-blob.c b/ui-blob.c
index 3cda03d..2ccd31d 100644
--- a/ui-blob.c
+++ b/ui-blob.c
@@ -29,3 +29,3 @@ void cgit_print_blob(const char *hex, char *path, const char *head)
enum object_type type;
- unsigned char *buf;
+ char *buf;
unsigned long size;
@@ -69,2 +69,8 @@ void cgit_print_blob(const char *hex, char *path, const char *head)
ctx.page.mimetype = ctx.qry.mimetype;
+ if (!ctx.page.mimetype) {
+ if (buffer_is_binary(buf, size))
+ ctx.page.mimetype = "application/octet-stream";
+ else
+ ctx.page.mimetype = "text/plain";
+ }
ctx.page.filename = path;
diff --git a/ui-plain.c b/ui-plain.c
index 5addd9e..93a3a05 100644
--- a/ui-plain.c
+++ b/ui-plain.c
@@ -33,5 +33,9 @@ static void print_object(const unsigned char *sha1, const char *path)
}
- ctx.page.mimetype = "text/plain";
+ if (buffer_is_binary(buf, size))
+ ctx.page.mimetype = "application/octet-stream";
+ else
+ ctx.page.mimetype = "text/plain";
ctx.page.filename = fmt("%s", path);
ctx.page.size = size;
+ ctx.page.etag = sha1_to_hex(sha1);
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)
+char *cgit_httpscheme()
+{
+ char *https;
+
+ https = getenv("HTTPS");
+ if (https != NULL && strcmp(https, "on") == 0)
+ return "https://";
+ else
+ return "http://";
+}
+
char *cgit_hosturl()
@@ -458,2 +469,6 @@ 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)
@@ -470,3 +485,7 @@ void cgit_print_http_headers(struct cgit_context *ctx)
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);
}
@@ -494,3 +513,4 @@ void cgit_print_docstart(struct cgit_context *ctx)
if (host && ctx->repo) {
- html("<link rel='alternate' title='Atom feed' href='http://");
+ html("<link rel='alternate' title='Atom feed' href='");
+ html(cgit_httpscheme());
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 @@
+extern char *cgit_httpscheme();
extern char *cgit_hosturl();