diff options
| author | 2009-08-10 15:21:09 (JST) | |
|---|---|---|
| committer | 2009-08-10 15:21:09 (JST) | |
| commit | 60a26272e0ca529407fe6b613f061f04ba585d53 (patch) | |
| tree | c2b6ee3c19a44bd276043650298229c481ca4535 /ui-shared.c | |
| parent | e6cd7121edf55c13f04cd5d6fca8f07c4035ce0a (diff) | |
| download | cgit-60a26272e0ca529407fe6b613f061f04ba585d53.zip cgit-60a26272e0ca529407fe6b613f061f04ba585d53.tar.gz | |
Cleanup handling of environment variables
Signed-off-by: Lars Hjemli <hjemli@gmail.com>
Diffstat (limited to 'ui-shared.c')
| -rw-r--r-- | ui-shared.c | 32 |
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 | |||
| @@ -36,10 +36,7 @@ void cgit_print_error(char *msg) | |||
| 36 | 36 | ||
| 37 | char *cgit_httpscheme() | 37 | char *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://"; |
| @@ -47,22 +44,13 @@ char *cgit_httpscheme() | |||
| 47 | 44 | ||
| 48 | char *cgit_hosturl() | 45 | char *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 | ||
| 68 | char *cgit_rooturl() | 56 | char *cgit_rooturl() |
| @@ -467,8 +455,6 @@ void cgit_print_age(time_t t, time_t max_relative, char *format) | |||
| 467 | 455 | ||
| 468 | void cgit_print_http_headers(struct cgit_context *ctx) | 456 | void 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 | ||
| @@ -489,7 +475,7 @@ void cgit_print_http_headers(struct cgit_context *ctx) | |||
| 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 | ||
