diff options
author | Ian Bicking <ianb@colorstudy.com> | 2010-08-20 13:40:16 -0500 |
---|---|---|
committer | Ian Bicking <ianb@colorstudy.com> | 2010-08-20 13:40:16 -0500 |
commit | 3c8acd42b9e89f3d4deacd5c3d5f6ff5cbf2acd5 (patch) | |
tree | a5e3ccaf49fc54344b30a1597e464f52d2034a70 | |
parent | 29d62c6d63199fd9739daf3fa362654b2a512c50 (diff) | |
download | paste-3c8acd42b9e89f3d4deacd5c3d5f6ff5cbf2acd5.tar.gz |
Fix problem with CGI apps that don't give a status message, and which mix \n and \r\n in their headers
-rw-r--r-- | paste/cgiapp.py | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/paste/cgiapp.py b/paste/cgiapp.py index e1ede03..ac6fd73 100644 --- a/paste/cgiapp.py +++ b/paste/cgiapp.py @@ -6,6 +6,7 @@ Application that runs a CGI script. """ import os import subprocess +import urllib try: import select except ImportError: @@ -30,7 +31,7 @@ class CGIApplication(object): a path, then ``$PATH`` will be used. """ - def __init__(self, + def __init__(self, global_conf, script, path=None, @@ -67,8 +68,8 @@ class CGIApplication(object): def __call__(self, environ, start_response): if 'REQUEST_URI' not in environ: environ['REQUEST_URI'] = ( - environ.get('SCRIPT_NAME', '') - + environ.get('PATH_INFO', '')) + urllib.quote(environ.get('SCRIPT_NAME', '')) + + urllib.quote(environ.get('PATH_INFO', ''))) if self.include_os_environ: cgi_environ = os.environ.copy() else: @@ -125,7 +126,7 @@ class CGIWriter(object): return self.buffer += data while '\n' in self.buffer: - if '\r\n' in self.buffer: + if '\r\n' in self.buffer and self.buffer.find('\r\n') < self.buffer.find('\n'): line1, self.buffer = self.buffer.split('\r\n', 1) else: line1, self.buffer = self.buffer.split('\n', 1) @@ -146,6 +147,9 @@ class CGIWriter(object): value = value.lstrip() name = name.strip() if name.lower() == 'status': + if ' ' not in value: + # WSGI requires this space, sometimes CGI scripts don't set it: + value = '%s General' % value self.status = value else: self.headers.append((name, value)) @@ -252,12 +256,12 @@ def proc_communicate(proc, stdin=None, stdout=None, stderr=None): except OSError, e: if e.errno != 10: raise - + def make_cgi_application(global_conf, script, path=None, include_os_environ=None, query_string=None): """ Paste Deploy interface for :class:`CGIApplication` - + This object acts as a proxy to a CGI application. You pass in the script path (``script``), an optional path to search for the script (if the name isn't absolute) (``path``). If you don't give |