Skip to content
Permalink
Browse files

Use X-FORWARDED-* headers when contructing onlineresource (#4955)

  • Loading branch information
tbonfort committed Jul 17, 2014
1 parent 5d433c6 commit 3241921a5d52b34c3d93b6f0b88f82779de27f26
Showing with 22 additions and 3 deletions.
  1. +22 −3 maputil.c
@@ -2366,10 +2366,23 @@ char *msBuildOnlineResource(mapObj *map, cgiRequestObj *req)
{
char *online_resource = NULL;
const char *value, *hostname, *port, *script, *protocol="http", *mapparam=NULL;
int mapparam_len = 0;
char **hostname_array = NULL;
int mapparam_len = 0, hostname_array_len = 0;

hostname = getenv("HTTP_X_FORWARDED_HOST");
if(!hostname)
hostname = getenv("SERVER_NAME");
else {
if(strchr(hostname,',')) {
hostname_array = msStringSplit(hostname,',', &hostname_array_len);
hostname = hostname_array[0];
}
}

hostname = getenv("SERVER_NAME");
port = getenv("SERVER_PORT");
port = getenv("HTTP_X_FORWARDED_PORT");
if(!port)
port = getenv("SERVER_PORT");

script = getenv("SCRIPT_NAME");

/* HTTPS is set by Apache to "on" in an HTTPS server ... if not set */
@@ -2378,6 +2391,9 @@ char *msBuildOnlineResource(mapObj *map, cgiRequestObj *req)
((value=getenv("SERVER_PORT")) && atoi(value) == 443) ) {
protocol = "https";
}
if ( (value=getenv("HTTP_X_FORWARDED_PROTO")) ) {
protocol = value;
}

/* If map=.. was explicitly set then we'll include it in onlineresource
*/
@@ -2411,6 +2427,9 @@ char *msBuildOnlineResource(mapObj *map, cgiRequestObj *req)
msSetError(MS_CGIERR, "Impossible to establish server URL.", "msBuildOnlineResource()");
return NULL;
}
if(hostname_array) {
msFreeCharArray(hostname_array, hostname_array_len);
}

return online_resource;
}

0 comments on commit 3241921

Please sign in to comment.
You can’t perform that action at this time.