call*cgi, python: Added symmetrical {SERVER,REMOTE}_{ADDR,PORT} parameters.
authorFredrik Tolf <fredrik@dolda2000.com>
Thu, 27 Dec 2012 17:41:21 +0000 (18:41 +0100)
committerFredrik Tolf <fredrik@dolda2000.com>
Thu, 27 Dec 2012 17:41:21 +0000 (18:41 +0100)
python/ashd-wsgi
python3/ashd-wsgi3
src/callcgi.c
src/callfcgi.c
src/callscgi.c

index 46cf85c..2e4a2fe 100755 (executable)
@@ -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
index dcf1613..8944b5c 100755 (executable)
@@ -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
index 3a28880..11fb213 100644 (file)
@@ -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"))
index 99d21ca..3320f5d 100644 (file)
@@ -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)
index 299e09f..e388ab2 100644 (file)
@@ -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)