]> gitweb.ps.run Git - ps-cgit/commitdiff
Merge branch 'ml/head-include'
authorLars Hjemli <hjemli@gmail.com>
Sat, 25 Jul 2009 10:04:08 +0000 (12:04 +0200)
committerLars Hjemli <hjemli@gmail.com>
Sat, 25 Jul 2009 10:04:08 +0000 (12:04 +0200)
1  2 
cgit.c
cgit.h
ui-shared.c

diff --combined cgit.c
index ae2025709a05b4f888e9fc090005c5a1a9ed10be,2afc5988afa1261b3adacfd4d8c307838766c1cb..513ea125bb196a065a4b1cc24f24cae0f571de52
--- 1/cgit.c
--- 2/cgit.c
+++ b/cgit.c
@@@ -31,6 -31,8 +31,8 @@@ void config_cb(const char *name, const 
                ctx.cfg.favicon = xstrdup(value);
        else if (!strcmp(name, "footer"))
                ctx.cfg.footer = xstrdup(value);
+       else if (!strcmp(name, "head-include"))
+               ctx.cfg.head_include = xstrdup(value);
        else if (!strcmp(name, "header"))
                ctx.cfg.header = xstrdup(value);
        else if (!strcmp(name, "logo"))
@@@ -206,7 -208,6 +208,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 {
@@@ -286,8 -287,6 +288,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);
@@@ -432,7 -431,6 +434,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 07a277a3e727b93b64623d4fa366ac3131486bdd,aed826afe589484ac60b7184460741c899eecbf7..78b30bace9327dc310dd646fa1ad86bdecd64ce6
--- 1/cgit.h
--- 2/cgit.h
+++ b/cgit.h
@@@ -136,6 -136,7 +136,7 @@@ struct cgit_config 
        char *css;
        char *favicon;
        char *footer;
+       char *head_include;
        char *header;
        char *index_header;
        char *index_info;
@@@ -180,10 -181,7 +181,10 @@@ struct cgit_page 
        char *mimetype;
        char *charset;
        char *filename;
 +      char *etag;
        char *title;
 +      int status;
 +      char *statusmsg;
  };
  
  struct cgit_context {
diff --combined ui-shared.c
index 10be3c057dab494ad9782220374d0df258247cf0,fea2c4054c736b53bf97f7dc735016e94663f0c4..66d5b8220de122d69a8398119592f09114c83731
@@@ -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,10 -456,6 +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)));
-               html("' type='application/atom+xml'/>");
+               html("' type='application/atom+xml'/>\n");
        }
+       if (ctx->cfg.head_include)
+               html_include(ctx->cfg.head_include);
        html("</head>\n");
        html("<body>\n");
        if (ctx->cfg.header)