aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Eric Wong <normalperson@yhbt.net>2008-09-01 15:30:33 (JST)
committerGravatar Lars Hjemli <hjemli@gmail.com>2008-09-02 08:26:37 (JST)
commit9c931b1e6e68f8dc891a5653035c3d70038ae3c0 (patch)
treea5cd6d953eb66ad77eb4e5b088e2022973fc4f61
parent687fb6d833d25144c86d1841fe0eca611f1eaeb1 (diff)
downloadcgit-9c931b1e6e68f8dc891a5653035c3d70038ae3c0.zip
cgit-9c931b1e6e68f8dc891a5653035c3d70038ae3c0.tar.gz
use Host: header to generate cgit_hosturl
I run an instance of lighttpd for cgit behind nginx (nginx doesn't execute CGI). So the port (SERVER_PORT=33333) that lighttpd runs on sends to cgit is different from the standard port 80 that public clients connect to (via nginx). This was causing the Atom feed URL to show the private port number that lighttpd was running on. Since the HTTP/1.1 "Host" header includes the port number if running on a non-standard port, it allows non-client-facing HTTP servers to transparently generate public URLs that clients can see. So use the "Host" header if it is available and fall back to SERVER_NAME/SERVER_PORT for some clients that don't set HTTP_HOST. Signed-off-by: Eric Wong <normalperson@yhbt.net>
-rw-r--r--ui-shared.c19
1 files changed, 12 insertions, 7 deletions
diff --git a/ui-shared.c b/ui-shared.c
index 4818e70..c23bc75 100644
--- a/ui-shared.c
+++ b/ui-shared.c
@@ -38,14 +38,19 @@ char *cgit_hosturl()
38{ 38{
39 char *host, *port; 39 char *host, *port;
40 40
41 host = getenv("SERVER_NAME"); 41 host = getenv("HTTP_HOST");
42 if (!host) 42 if (host) {
43 return NULL;
44 port = getenv("SERVER_PORT");
45 if (port && atoi(port) != 80)
46 host = xstrdup(fmt("%s:%d", host, atoi(port)));
47 else
48 host = xstrdup(host); 43 host = xstrdup(host);
44 } else {
45 host = getenv("SERVER_NAME");
46 if (!host)
47 return NULL;
48 port = getenv("SERVER_PORT");
49 if (port && atoi(port) != 80)
50 host = xstrdup(fmt("%s:%d", host, atoi(port)));
51 else
52 host = xstrdup(host);
53 }
49 return host; 54 return host;
50} 55}
51 56