##// END OF EJS Templates
hgweb: when constructing or adding to a wsgi environ dict, use native strs...
Augie Fackler -
r34513:482d6f6d default
parent child Browse files
Show More
@@ -59,15 +59,15 b' class wsgirequest(object):'
59 for obtaining request parameters, writing HTTP output, etc.
59 for obtaining request parameters, writing HTTP output, etc.
60 """
60 """
61 def __init__(self, wsgienv, start_response):
61 def __init__(self, wsgienv, start_response):
62 version = wsgienv['wsgi.version']
62 version = wsgienv[r'wsgi.version']
63 if (version < (1, 0)) or (version >= (2, 0)):
63 if (version < (1, 0)) or (version >= (2, 0)):
64 raise RuntimeError("Unknown and unsupported WSGI version %d.%d"
64 raise RuntimeError("Unknown and unsupported WSGI version %d.%d"
65 % version)
65 % version)
66 self.inp = wsgienv['wsgi.input']
66 self.inp = wsgienv[r'wsgi.input']
67 self.err = wsgienv['wsgi.errors']
67 self.err = wsgienv[r'wsgi.errors']
68 self.threaded = wsgienv['wsgi.multithread']
68 self.threaded = wsgienv[r'wsgi.multithread']
69 self.multiprocess = wsgienv['wsgi.multiprocess']
69 self.multiprocess = wsgienv[r'wsgi.multiprocess']
70 self.run_once = wsgienv['wsgi.run_once']
70 self.run_once = wsgienv[r'wsgi.run_once']
71 self.env = wsgienv
71 self.env = wsgienv
72 self.form = normalize(cgi.parse(self.inp,
72 self.form = normalize(cgi.parse(self.inp,
73 self.env,
73 self.env,
@@ -63,7 +63,7 b' class _httprequesthandler(httpservermod.'
63 """Prepare .socket of new HTTPServer instance"""
63 """Prepare .socket of new HTTPServer instance"""
64
64
65 def __init__(self, *args, **kargs):
65 def __init__(self, *args, **kargs):
66 self.protocol_version = 'HTTP/1.1'
66 self.protocol_version = r'HTTP/1.1'
67 httpservermod.basehttprequesthandler.__init__(self, *args, **kargs)
67 httpservermod.basehttprequesthandler.__init__(self, *args, **kargs)
68
68
69 def _log_any(self, fp, format, *args):
69 def _log_any(self, fp, format, *args):
@@ -112,45 +112,45 b' class _httprequesthandler(httpservermod.'
112 path, query = _splitURI(self.path)
112 path, query = _splitURI(self.path)
113
113
114 env = {}
114 env = {}
115 env['GATEWAY_INTERFACE'] = 'CGI/1.1'
115 env[r'GATEWAY_INTERFACE'] = r'CGI/1.1'
116 env['REQUEST_METHOD'] = self.command
116 env[r'REQUEST_METHOD'] = self.command
117 env['SERVER_NAME'] = self.server.server_name
117 env[r'SERVER_NAME'] = self.server.server_name
118 env['SERVER_PORT'] = str(self.server.server_port)
118 env[r'SERVER_PORT'] = str(self.server.server_port)
119 env['REQUEST_URI'] = self.path
119 env[r'REQUEST_URI'] = self.path
120 env['SCRIPT_NAME'] = self.server.prefix
120 env[r'SCRIPT_NAME'] = self.server.prefix
121 env['PATH_INFO'] = path[len(self.server.prefix):]
121 env[r'PATH_INFO'] = path[len(self.server.prefix):]
122 env['REMOTE_HOST'] = self.client_address[0]
122 env[r'REMOTE_HOST'] = self.client_address[0]
123 env['REMOTE_ADDR'] = self.client_address[0]
123 env[r'REMOTE_ADDR'] = self.client_address[0]
124 if query:
124 if query:
125 env['QUERY_STRING'] = query
125 env[r'QUERY_STRING'] = query
126
126
127 if self.headers.typeheader is None:
127 if self.headers.typeheader is None:
128 env['CONTENT_TYPE'] = self.headers.type
128 env[r'CONTENT_TYPE'] = self.headers.type
129 else:
129 else:
130 env['CONTENT_TYPE'] = self.headers.typeheader
130 env[r'CONTENT_TYPE'] = self.headers.typeheader
131 length = self.headers.getheader('content-length')
131 length = self.headers.getheader('content-length')
132 if length:
132 if length:
133 env['CONTENT_LENGTH'] = length
133 env[r'CONTENT_LENGTH'] = length
134 for header in [h for h in self.headers.keys()
134 for header in [h for h in self.headers.keys()
135 if h not in ('content-type', 'content-length')]:
135 if h not in ('content-type', 'content-length')]:
136 hkey = 'HTTP_' + header.replace('-', '_').upper()
136 hkey = r'HTTP_' + header.replace(r'-', r'_').upper()
137 hval = self.headers.getheader(header)
137 hval = self.headers.get(header)
138 hval = hval.replace('\n', '').strip()
138 hval = hval.replace(r'\n', r'').strip()
139 if hval:
139 if hval:
140 env[hkey] = hval
140 env[hkey] = hval
141 env['SERVER_PROTOCOL'] = self.request_version
141 env[r'SERVER_PROTOCOL'] = self.request_version
142 env['wsgi.version'] = (1, 0)
142 env[r'wsgi.version'] = (1, 0)
143 env['wsgi.url_scheme'] = self.url_scheme
143 env[r'wsgi.url_scheme'] = self.url_scheme
144 if env.get('HTTP_EXPECT', '').lower() == '100-continue':
144 if env.get(r'HTTP_EXPECT', '').lower() == '100-continue':
145 self.rfile = common.continuereader(self.rfile, self.wfile.write)
145 self.rfile = common.continuereader(self.rfile, self.wfile.write)
146
146
147 env['wsgi.input'] = self.rfile
147 env[r'wsgi.input'] = self.rfile
148 env['wsgi.errors'] = _error_logger(self)
148 env[r'wsgi.errors'] = _error_logger(self)
149 env['wsgi.multithread'] = isinstance(self.server,
149 env[r'wsgi.multithread'] = isinstance(self.server,
150 socketserver.ThreadingMixIn)
150 socketserver.ThreadingMixIn)
151 env['wsgi.multiprocess'] = isinstance(self.server,
151 env[r'wsgi.multiprocess'] = isinstance(self.server,
152 socketserver.ForkingMixIn)
152 socketserver.ForkingMixIn)
153 env['wsgi.run_once'] = 0
153 env[r'wsgi.run_once'] = 0
154
154
155 self.saved_status = None
155 self.saved_status = None
156 self.saved_headers = []
156 self.saved_headers = []
@@ -24,28 +24,28 b' def launch(application):'
24 util.setbinary(util.stdout)
24 util.setbinary(util.stdout)
25
25
26 environ = dict(encoding.environ.iteritems())
26 environ = dict(encoding.environ.iteritems())
27 environ.setdefault('PATH_INFO', '')
27 environ.setdefault(r'PATH_INFO', '')
28 if environ.get('SERVER_SOFTWARE', '').startswith('Microsoft-IIS'):
28 if environ.get(r'SERVER_SOFTWARE', r'').startswith(r'Microsoft-IIS'):
29 # IIS includes script_name in PATH_INFO
29 # IIS includes script_name in PATH_INFO
30 scriptname = environ['SCRIPT_NAME']
30 scriptname = environ[r'SCRIPT_NAME']
31 if environ['PATH_INFO'].startswith(scriptname):
31 if environ[r'PATH_INFO'].startswith(scriptname):
32 environ['PATH_INFO'] = environ['PATH_INFO'][len(scriptname):]
32 environ[r'PATH_INFO'] = environ[r'PATH_INFO'][len(scriptname):]
33
33
34 stdin = util.stdin
34 stdin = util.stdin
35 if environ.get('HTTP_EXPECT', '').lower() == '100-continue':
35 if environ.get(r'HTTP_EXPECT', r'').lower() == r'100-continue':
36 stdin = common.continuereader(stdin, util.stdout.write)
36 stdin = common.continuereader(stdin, util.stdout.write)
37
37
38 environ['wsgi.input'] = stdin
38 environ[r'wsgi.input'] = stdin
39 environ['wsgi.errors'] = util.stderr
39 environ[r'wsgi.errors'] = util.stderr
40 environ['wsgi.version'] = (1, 0)
40 environ[r'wsgi.version'] = (1, 0)
41 environ['wsgi.multithread'] = False
41 environ[r'wsgi.multithread'] = False
42 environ['wsgi.multiprocess'] = True
42 environ[r'wsgi.multiprocess'] = True
43 environ['wsgi.run_once'] = True
43 environ[r'wsgi.run_once'] = True
44
44
45 if environ.get('HTTPS', 'off').lower() in ('on', '1', 'yes'):
45 if environ.get(r'HTTPS', r'off').lower() in (r'on', r'1', r'yes'):
46 environ['wsgi.url_scheme'] = 'https'
46 environ[r'wsgi.url_scheme'] = r'https'
47 else:
47 else:
48 environ['wsgi.url_scheme'] = 'http'
48 environ[r'wsgi.url_scheme'] = r'http'
49
49
50 headers_set = []
50 headers_set = []
51 headers_sent = []
51 headers_sent = []
General Comments 0
You need to be logged in to leave comments. Login now