summaryrefslogtreecommitdiffabout
path: root/ui-shared.c
authorLars Hjemli <hjemli@gmail.com>2009-08-10 06:21:09 (UTC)
committer Lars Hjemli <hjemli@gmail.com>2009-08-10 06:21:09 (UTC)
commit60a26272e0ca529407fe6b613f061f04ba585d53 (patch) (unidiff)
treec2b6ee3c19a44bd276043650298229c481ca4535 /ui-shared.c
parente6cd7121edf55c13f04cd5d6fca8f07c4035ce0a (diff)
downloadcgit-60a26272e0ca529407fe6b613f061f04ba585d53.zip
cgit-60a26272e0ca529407fe6b613f061f04ba585d53.tar.gz
cgit-60a26272e0ca529407fe6b613f061f04ba585d53.tar.bz2
Cleanup handling of environment variables
Signed-off-by: Lars Hjemli <hjemli@gmail.com>
Diffstat (limited to 'ui-shared.c') (more/less context) (ignore whitespace changes)
-rw-r--r--ui-shared.c32
1 files changed, 9 insertions, 23 deletions
diff --git a/ui-shared.c b/ui-shared.c
index 015c52b..538ddda 100644
--- a/ui-shared.c
+++ b/ui-shared.c
@@ -33,39 +33,27 @@ void cgit_print_error(char *msg)
33 html_txt(msg); 33 html_txt(msg);
34 html("</div>\n"); 34 html("</div>\n");
35} 35}
36 36
37char *cgit_httpscheme() 37char *cgit_httpscheme()
38{ 38{
39 char *https; 39 if (ctx.env.https && !strcmp(ctx.env.https, "on"))
40
41 https = getenv("HTTPS");
42 if (https != NULL && strcmp(https, "on") == 0)
43 return "https://"; 40 return "https://";
44 else 41 else
45 return "http://"; 42 return "http://";
46} 43}
47 44
48char *cgit_hosturl() 45char *cgit_hosturl()
49{ 46{
50 char *host, *port; 47 if (ctx.env.http_host)
51 48 return ctx.env.http_host;
52 host = getenv("HTTP_HOST"); 49 if (!ctx.env.server_name)
53 if (host) { 50 return NULL;
54 host = xstrdup(host); 51 if (!ctx.env.server_port || atoi(ctx.env.server_port) == 80)
55 } else { 52 return ctx.env.server_name;
56 host = getenv("SERVER_NAME"); 53 return xstrdup(fmt("%s:%s", ctx.env.server_name, ctx.env.server_port));
57 if (!host)
58 return NULL;
59 port = getenv("SERVER_PORT");
60 if (port && atoi(port) != 80)
61 host = xstrdup(fmt("%s:%d", host, atoi(port)));
62 else
63 host = xstrdup(host);
64 }
65 return host;
66} 54}
67 55
68char *cgit_rooturl() 56char *cgit_rooturl()
69{ 57{
70 if (ctx.cfg.virtual_root) 58 if (ctx.cfg.virtual_root)
71 return fmt("%s/", ctx.cfg.virtual_root); 59 return fmt("%s/", ctx.cfg.virtual_root);
@@ -464,14 +452,12 @@ void cgit_print_age(time_t t, time_t max_relative, char *format)
464 htmlf("<span class='age-years'>%.0f years</span>", 452 htmlf("<span class='age-years'>%.0f years</span>",
465 secs * 1.0 / TM_YEAR); 453 secs * 1.0 / TM_YEAR);
466} 454}
467 455
468void cgit_print_http_headers(struct cgit_context *ctx) 456void cgit_print_http_headers(struct cgit_context *ctx)
469{ 457{
470 const char *method = getenv("REQUEST_METHOD");
471
472 if (ctx->cfg.embedded) 458 if (ctx->cfg.embedded)
473 return; 459 return;
474 460
475 if (ctx->page.status) 461 if (ctx->page.status)
476 htmlf("Status: %d %s\n", ctx->page.status, ctx->page.statusmsg); 462 htmlf("Status: %d %s\n", ctx->page.status, ctx->page.statusmsg);
477 if (ctx->page.mimetype && ctx->page.charset) 463 if (ctx->page.mimetype && ctx->page.charset)
@@ -486,13 +472,13 @@ void cgit_print_http_headers(struct cgit_context *ctx)
486 ctx->page.filename); 472 ctx->page.filename);
487 htmlf("Last-Modified: %s\n", http_date(ctx->page.modified)); 473 htmlf("Last-Modified: %s\n", http_date(ctx->page.modified));
488 htmlf("Expires: %s\n", http_date(ctx->page.expires)); 474 htmlf("Expires: %s\n", http_date(ctx->page.expires));
489 if (ctx->page.etag) 475 if (ctx->page.etag)
490 htmlf("ETag: \"%s\"\n", ctx->page.etag); 476 htmlf("ETag: \"%s\"\n", ctx->page.etag);
491 html("\n"); 477 html("\n");
492 if (method && !strcmp(method, "HEAD")) 478 if (ctx->env.request_method && !strcmp(ctx->env.request_method, "HEAD"))
493 exit(0); 479 exit(0);
494} 480}
495 481
496void cgit_print_docstart(struct cgit_context *ctx) 482void cgit_print_docstart(struct cgit_context *ctx)
497{ 483{
498 if (ctx->cfg.embedded) 484 if (ctx->cfg.embedded)