summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--wsgitools/scgi/__init__.py15
-rw-r--r--wsgitools/scgi/asynchronous.py22
-rw-r--r--wsgitools/scgi/forkpool.py19
3 files changed, 25 insertions, 31 deletions
diff --git a/wsgitools/scgi/__init__.py b/wsgitools/scgi/__init__.py
index e69de29..20f6625 100644
--- a/wsgitools/scgi/__init__.py
+++ b/wsgitools/scgi/__init__.py
@@ -0,0 +1,15 @@
+def _convert_environ(environ, multithread=False, multiprocess=False,
+ run_once=False):
+ environ.update({
+ "wsgi.version": (1, 0),
+ "wsgi.url_scheme": "http",
+ "wsgi.multithread": multithread,
+ "wsgi.multiprocess": multiprocess,
+ "wsgi.run_once": run_once})
+ if environ.get("HTTPS", "no").lower() in ('yes', 'y', 'on', '1'):
+ environ["wsgi.url_scheme"] = "https"
+ try:
+ environ["CONTENT_TYPE"] = environ.pop("HTTP_CONTENT_TYPE")
+ except KeyError:
+ pass
+ environ.pop("HTTP_CONTENT_LENGTH", None) # TODO: better way?
diff --git a/wsgitools/scgi/asynchronous.py b/wsgitools/scgi/asynchronous.py
index 6b69c73..4ecb00a 100644
--- a/wsgitools/scgi/asynchronous.py
+++ b/wsgitools/scgi/asynchronous.py
@@ -11,6 +11,8 @@ except ImportError:
import StringIO as io
import errno
+from wsgitools.scgi import _convert_environ
+
if sys.version_info[0] >= 3:
def exc_info_for_raise(exc_info):
return exc_info[0](exc_info[1]).with_traceback(exc_info[2])
@@ -44,15 +46,6 @@ class SCGIConnection(asyncore.dispatcher):
# () -> unset, (..,..) -> set, True -> sent
self.body = io.StringIO() # request body
- def _wsgi_headers(self):
- return {"wsgi.version": (1, 0),
- "wsgi.input": self.body,
- "wsgi.errors": self.server.error,
- "wsgi.url_scheme": "http",
- "wsgi.multithread": False,
- "wsgi.multiprocess": False,
- "wsgi.run_once": False}
-
def _try_send_headers(self):
if self.outheaders != True:
assert not self.outbuff
@@ -128,14 +121,9 @@ class SCGIConnection(asyncore.dispatcher):
self.body.seek(0)
self.inbuff = ""
self.reqlen = 0
- self.environ.update(self._wsgi_headers())
- if self.environ.get("HTTPS", "no").lower() in ('yes', 'y', '1'):
- self.environ["wsgi.url_scheme"] = "https"
- if "HTTP_CONTENT_TYPE" in self.environ:
- self.environ["CONTENT_TYPE"] = \
- self.environ.pop("HTTP_CONTENT_TYPE")
- if "HTTP_CONTENT_LENGTH" in self.environ:
- del self.environ["HTTP_CONTENT_LENGTH"] # TODO: better way?
+ _convert_environ(self.environ)
+ self.environ["wsgi.input"] = self.body
+ self.environ["wsgi.errors"] = self.server.error
self.wsgihandler = iter(self.server.wsgiapp(
self.environ, self.start_response))
self.state = SCGIConnection.REQ
diff --git a/wsgitools/scgi/forkpool.py b/wsgitools/scgi/forkpool.py
index 39c9dfd..d4e67d4 100644
--- a/wsgitools/scgi/forkpool.py
+++ b/wsgitools/scgi/forkpool.py
@@ -12,6 +12,8 @@ import sys
import errno
import signal
+from wsgitools.scgi import _convert_environ
+
if sys.version_info[0] >= 3:
def exc_info_for_raise(exc_info):
return exc_info[0](exc_info[1]).with_traceback(exc_info[2])
@@ -431,21 +433,10 @@ class SCGIServer:
con.close()
return
+ _convert_environ(environ, multiprocess=True)
sfw = SocketFileWrapper(con, int(environ["CONTENT_LENGTH"]))
- environ.update({
- "wsgi.version": (1, 0),
- "wsgi.input": sfw,
- "wsgi.errors": self.error,
- "wsgi.url_scheme": "http",
- "wsgi.multithread": False,
- "wsgi.multiprocess": True,
- "wsgi.run_once": False})
- if environ.get("HTTPS", "no").lower() in ('yes', 'y', '1'):
- environ["wsgi.url_scheme"] = "https"
- if "HTTP_CONTENT_TYPE" in environ:
- environ["CONTENT_TYPE"] = environ.pop("HTTP_CONTENT_TYPE")
- if "HTTP_CONTENT_LENGTH" in environ:
- del environ["HTTP_CONTENT_LENGTH"] # TODO: better way?
+ environ["wsgi.input"] = sfw
+ environ["wsgi.errors"] = self.error
result = self.wsgiapp(environ, start_response)
assert hasattr(result, "__iter__")