]> gitweb.ps.run Git - ps-cgit/commitdiff
Merge branch 'plain-etag'
authorLars Hjemli <hjemli@gmail.com>
Sat, 25 Jul 2009 09:59:22 +0000 (11:59 +0200)
committerLars Hjemli <hjemli@gmail.com>
Sat, 25 Jul 2009 09:59:22 +0000 (11:59 +0200)
Conflicts:
ui-shared.c

1  2 
cgit.c
cgit.h
ui-plain.c
ui-shared.c

diff --combined cgit.c
index 19adadd2e3a9277aa25916eb1747ee3cbae63f75,dc1c2e453de7ecb880df9d89a125196a66ad58eb..ae2025709a05b4f888e9fc090005c5a1a9ed10be
--- 1/cgit.c
--- 2/cgit.c
+++ b/cgit.c
@@@ -206,6 -206,7 +206,7 @@@ static void prepare_context(struct cgit
        ctx->page.size = 0;
        ctx->page.modified = time(NULL);
        ctx->page.expires = ctx->page.modified;
+       ctx->page.etag = NULL;
  }
  
  struct refmatch {
@@@ -285,8 -286,6 +286,8 @@@ static int prepare_repo_cmd(struct cgit
        if (get_sha1(ctx->qry.head, sha1)) {
                tmp = xstrdup(ctx->qry.head);
                ctx->qry.head = ctx->repo->defbranch;
 +              ctx->page.status = 404;
 +              ctx->page.statusmsg = "not found";
                cgit_print_http_headers(ctx);
                cgit_print_docstart(ctx);
                cgit_print_pageheader(ctx);
@@@ -431,6 -430,7 +432,7 @@@ static int calc_ttl(
  int main(int argc, const char **argv)
  {
        const char *cgit_config_env = getenv("CGIT_CONFIG");
+       const char *method = getenv("REQUEST_METHOD");
        const char *path;
        char *qry;
        int err, ttl;
  
        ttl = calc_ttl();
        ctx.page.expires += ttl*60;
+       if (method && !strcmp(method, "HEAD"))
+               ctx.cfg.nocache = 1;
        if (ctx.cfg.nocache)
                ctx.cfg.cache_size = 0;
        err = cache_process(ctx.cfg.cache_size, ctx.cfg.cache_root,
diff --combined cgit.h
index 00aca4c36a46d6dc8737b32ea794c917dcfc825e,2bfbe7b0007ae65939cf972bd9cd3eb3093fef48..07a277a3e727b93b64623d4fa366ac3131486bdd
--- 1/cgit.h
--- 2/cgit.h
+++ b/cgit.h
@@@ -180,9 -180,8 +180,10 @@@ struct cgit_page 
        char *mimetype;
        char *charset;
        char *filename;
+       char *etag;
        char *title;
 +      int status;
 +      char *statusmsg;
  };
  
  struct cgit_context {
diff --combined ui-plain.c
index 9a9ae7d5a80ccea3db7bea37a69405ca60e56edd,f73cd14e8e56e3b080fe73a647c5ff91ed2f58ed..93a3a05ac50f7a43b3c50529a011f0c9fdbf547c
@@@ -31,12 -31,10 +31,13 @@@ static void print_object(const unsigne
                html_status(404, "Not found", 0);
                return;
        }
 -      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);
        html_raw(buf, size);
        match = 1;
diff --combined ui-shared.c
index 29036d0a92ba45643e7db53af2671113fcbff7be,0dafc836736c1c8f165deb167c7b3a6f83302e0f..10be3c057dab494ad9782220374d0df258247cf0
@@@ -34,17 -34,6 +34,17 @@@ void cgit_print_error(char *msg
        html("</div>\n");
  }
  
 +char *cgit_httpscheme()
 +{
 +      char *https;
 +
 +      https = getenv("HTTPS");
 +      if (https != NULL && strcmp(https, "on") == 0)
 +              return "https://";
 +      else
 +              return "http://";
 +}
 +
  char *cgit_hosturl()
  {
        char *host, *port;
@@@ -467,8 -456,8 +467,10 @@@ void cgit_print_age(time_t t, time_t ma
  
  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)
                htmlf("Content-Type: %s; charset=%s\n", ctx->page.mimetype,
                      ctx->page.charset);
                      ctx->page.filename);
        htmlf("Last-Modified: %s\n", http_date(ctx->page.modified));
        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);
  }
  
  void cgit_print_docstart(struct cgit_context *ctx)
                html("'/>\n");
        }
        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());
                html_attr(cgit_fileurl(ctx->repo->url, "atom", ctx->qry.path,
                                       fmt("h=%s", ctx->qry.head)));