cgit

commit 91fd1eca07f9e48109e8acebc0a92dc4b12ecb50

Author: Lars Hjemli <hjemli@gmail.com>

Merge branch 'ew/http_host'

* ew/http_host:
  use Host: header to generate cgit_hosturl

 ui-shared.c | 19 ++++++++++++-------


diff --git a/ui-shared.c b/ui-shared.c
index 4818e70983064ac5e1d8d944e530365f240ed63e..c23bc7540b9862bb200afba1bd46b7af7a119896 100644
--- a/ui-shared.c
+++ b/ui-shared.c
@@ -38,14 +38,19 @@ char *cgit_hosturl()
 {
 	char *host, *port;
 
-	host = getenv("SERVER_NAME");
-	if (!host)
-		return NULL;
-	port = getenv("SERVER_PORT");
-	if (port && atoi(port) != 80)
-		host = xstrdup(fmt("%s:%d", host, atoi(port)));
-	else
+	host = getenv("HTTP_HOST");
+	if (host) {
 		host = xstrdup(host);
+	} else {
+		host = getenv("SERVER_NAME");
+		if (!host)
+			return NULL;
+		port = getenv("SERVER_PORT");
+		if (port && atoi(port) != 80)
+			host = xstrdup(fmt("%s:%d", host, atoi(port)));
+		else
+			host = xstrdup(host);
+	}
 	return host;
 }