From 1af656d2284a5f51631ae11ee9fa068af5c1ccc4 Mon Sep 17 00:00:00 2001 From: Fredrik Tolf Date: Thu, 27 Dec 2012 18:41:21 +0100 Subject: [PATCH] call*cgi, python: Added symmetrical {SERVER,REMOTE}_{ADDR,PORT} parameters. --- python/ashd-wsgi | 2 ++ python3/ashd-wsgi3 | 7 ++++--- src/callcgi.c | 4 ++++ src/callfcgi.c | 4 ++++ src/callscgi.c | 4 ++++ 5 files changed, 18 insertions(+), 3 deletions(-) diff --git a/python/ashd-wsgi b/python/ashd-wsgi index 46cf85c..2e4a2fe 100755 --- a/python/ashd-wsgi +++ b/python/ashd-wsgi @@ -127,9 +127,11 @@ def dowsgi(req): env["SCRIPT_NAME"] = name env["PATH_INFO"] = pi if "Host" in req: env["SERVER_NAME"] = req["Host"] + if "X-Ash-Server-Address" in req: env["SERVER_ADDR"] = req["X-Ash-Server-Address"] if "X-Ash-Server-Port" in req: env["SERVER_PORT"] = req["X-Ash-Server-Port"] if "X-Ash-Protocol" in req and req["X-Ash-Protocol"] == "https": env["HTTPS"] = "on" if "X-Ash-Address" in req: env["REMOTE_ADDR"] = req["X-Ash-Address"] + if "X-Ash-Port" in req: env["REMOTE_PORT"] = req["X-Ash-Port"] if "Content-Type" in req: env["CONTENT_TYPE"] = req["Content-Type"] # The CGI specification does not strictly require this, but diff --git a/python3/ashd-wsgi3 b/python3/ashd-wsgi3 index dcf1613..8944b5c 100755 --- a/python3/ashd-wsgi3 +++ b/python3/ashd-wsgi3 @@ -131,9 +131,10 @@ def dowsgi(req): name = "" env["SCRIPT_NAME"] = name env["PATH_INFO"] = pi - for src, tgt in [("HTTP_HOST", "SERVER_NAME"), ("HTTP_X_ASH_SERVER_PORT", "SERVER_PORT"), - ("HTTP_X_ASH_ADDRESS", "REMOTE_ADDR"), ("HTTP_CONTENT_TYPE", "CONTENT_TYPE"), - ("HTTP_CONTENT_LENGTH", "CONTENT_LENGTH"), ("HTTP_X_ASH_PROTOCOL", "wsgi.url_scheme")]: + for src, tgt in [("HTTP_HOST", "SERVER_NAME"), ("HTTP_X_ASH_PROTOCOL", "wsgi.url_scheme"), + ("HTTP_X_ASH_SERVER_ADDRESS", "SERVER_ADDR"), ("HTTP_X_ASH_SERVER_PORT", "SERVER_PORT"), + ("HTTP_X_ASH_ADDRESS", "REMOTE_ADDR"), ("HTTP_X_ASH_PORT", "REMOTE_PORT"), + ("HTTP_CONTENT_TYPE", "CONTENT_TYPE"), ("HTTP_CONTENT_LENGTH", "CONTENT_LENGTH")]: if src in env: env[tgt] = env[src] for key in ["HTTP_CONTENT_TYPE", "HTTP_CONTENT_LENGTH"]: # The CGI specification does not strictly require this, but diff --git a/src/callcgi.c b/src/callcgi.c index 3a28880..11fb213 100644 --- a/src/callcgi.c +++ b/src/callcgi.c @@ -145,12 +145,16 @@ static pid_t forkchild(int inpath, char *prog, char *file, char *method, char *u putenv(sprintf2("QUERY_STRING=%s", qp?qp:"")); if(getenv("REQ_HOST")) putenv(sprintf2("SERVER_NAME=%s", getenv("REQ_HOST"))); + if(getenv("REQ_X_ASH_SERVER_ADDRESS")) + putenv(sprintf2("SERVER_ADDR=%s", getenv("REQ_X_ASH_SERVER_ADDRESS"))); if(getenv("REQ_X_ASH_SERVER_PORT")) putenv(sprintf2("SERVER_PORT=%s", getenv("REQ_X_ASH_SERVER_PORT"))); if(getenv("REQ_X_ASH_PROTOCOL") && !strcmp(getenv("REQ_X_ASH_PROTOCOL"), "https")) putenv("HTTPS=on"); if(getenv("REQ_X_ASH_ADDRESS")) putenv(sprintf2("REMOTE_ADDR=%s", getenv("REQ_X_ASH_ADDRESS"))); + if(getenv("REQ_X_ASH_PORT")) + putenv(sprintf2("REMOTE_PORT=%s", getenv("REQ_X_ASH_PORT"))); if(getenv("REQ_X_ASH_REMOTE_USER")) putenv(sprintf2("REMOTE_USER=%s", getenv("REQ_X_ASH_REMOTE_USER"))); if(getenv("REQ_CONTENT_TYPE")) diff --git a/src/callfcgi.c b/src/callfcgi.c index 99d21ca..3320f5d 100644 --- a/src/callfcgi.c +++ b/src/callfcgi.c @@ -473,6 +473,8 @@ static void mkcgienv(struct hthead *req, struct charbuf *dst) free(url); if((h = getheader(req, "Host")) != NULL) bufaddenv(dst, "SERVER_NAME", "%s", h); + if((h = getheader(req, "X-Ash-Server-Address")) != NULL) + bufaddenv(dst, "SERVER_ADDR", "%s", h); if((h = getheader(req, "X-Ash-Server-Port")) != NULL) bufaddenv(dst, "SERVER_PORT", "%s", h); if((h = getheader(req, "X-Ash-Remote-User")) != NULL) @@ -481,6 +483,8 @@ static void mkcgienv(struct hthead *req, struct charbuf *dst) bufaddenv(dst, "HTTPS", "on"); if((h = getheader(req, "X-Ash-Address")) != NULL) bufaddenv(dst, "REMOTE_ADDR", "%s", h); + if((h = getheader(req, "X-Ash-Port")) != NULL) + bufaddenv(dst, "REMOTE_PORT", "%s", h); if((h = getheader(req, "Content-Type")) != NULL) bufaddenv(dst, "CONTENT_TYPE", "%s", h); if((h = getheader(req, "Content-Length")) != NULL) diff --git a/src/callscgi.c b/src/callscgi.c index 299e09f..e388ab2 100644 --- a/src/callscgi.c +++ b/src/callscgi.c @@ -436,6 +436,8 @@ static void mkcgienv(struct hthead *req, struct charbuf *dst) free(url); if((h = getheader(req, "Host")) != NULL) bufaddenv(dst, "SERVER_NAME", "%s", h); + if((h = getheader(req, "X-Ash-Server-Address")) != NULL) + bufaddenv(dst, "SERVER_ADDR", "%s", h); if((h = getheader(req, "X-Ash-Server-Port")) != NULL) bufaddenv(dst, "SERVER_PORT", "%s", h); if((h = getheader(req, "X-Ash-Remote-User")) != NULL) @@ -444,6 +446,8 @@ static void mkcgienv(struct hthead *req, struct charbuf *dst) bufaddenv(dst, "HTTPS", "on"); if((h = getheader(req, "X-Ash-Address")) != NULL) bufaddenv(dst, "REMOTE_ADDR", "%s", h); + if((h = getheader(req, "X-Ash-Port")) != NULL) + bufaddenv(dst, "REMOTE_PORT", "%s", h); if((h = getheader(req, "Content-Type")) != NULL) bufaddenv(dst, "CONTENT_TYPE", "%s", h); if((h = getheader(req, "Content-Length")) != NULL) -- 2.11.0