Add environ['RAW_PATH_INFO'] to hold the request path as it was sent from
the client. Add a test_path_info_decoding unit test to verify that both the unquoted PATH_INFO and raw RAW_PATH_INFO are set correctly.
This commit is contained in:
@@ -454,6 +454,7 @@ class HttpProtocol(BaseHTTPServer.BaseHTTPRequestHandler):
|
||||
env['SCRIPT_NAME'] = ''
|
||||
|
||||
pq = self.path.split('?', 1)
|
||||
env['RAW_PATH_INFO'] = pq[0]
|
||||
env['PATH_INFO'] = urllib.unquote(pq[0])
|
||||
if len(pq) > 1:
|
||||
env['QUERY_STRING'] = pq[1]
|
||||
|
@@ -622,8 +622,8 @@ class TestHttpd(_TestBase):
|
||||
for environ_var in ['wsgi.version', 'wsgi.url_scheme',
|
||||
'wsgi.input', 'wsgi.errors', 'wsgi.multithread',
|
||||
'wsgi.multiprocess', 'wsgi.run_once', 'REQUEST_METHOD',
|
||||
'SCRIPT_NAME', 'PATH_INFO', 'QUERY_STRING', 'CONTENT_TYPE',
|
||||
'CONTENT_LENGTH', 'SERVER_NAME', 'SERVER_PORT',
|
||||
'SCRIPT_NAME', 'RAW_PATH_INFO', 'PATH_INFO', 'QUERY_STRING',
|
||||
'CONTENT_TYPE', 'CONTENT_LENGTH', 'SERVER_NAME', 'SERVER_PORT',
|
||||
'SERVER_PROTOCOL']:
|
||||
environ[environ_var] = None
|
||||
start_response('200 OK', [('Content-type', 'text/plain')])
|
||||
@@ -975,6 +975,22 @@ class TestHttpd(_TestBase):
|
||||
self.assertEqual(headers['connection'], 'close')
|
||||
self.assert_('unicode' in body)
|
||||
|
||||
def test_path_info_decoding(self):
|
||||
def wsgi_app(environ, start_response):
|
||||
start_response("200 OK", [])
|
||||
yield "decoded: %s" % environ['PATH_INFO']
|
||||
yield "raw: %s" % environ['RAW_PATH_INFO']
|
||||
self.site.application = wsgi_app
|
||||
sock = eventlet.connect(('localhost', self.port))
|
||||
fd = sock.makefile('rw')
|
||||
fd.write('GET /a*b@%40%233 HTTP/1.1\r\nHost: localhost\r\nConnection: '\
|
||||
'close\r\n\r\n')
|
||||
fd.flush()
|
||||
response_line, headers, body = read_http(sock)
|
||||
self.assert_(response_line.startswith('HTTP/1.1 200'))
|
||||
self.assert_('decoded: /a*b@@#3' in body)
|
||||
self.assert_('raw: /a*b@%40%233' in body)
|
||||
|
||||
def test_ipv6(self):
|
||||
try:
|
||||
sock = eventlet.listen(('::1', 0), family=socket.AF_INET6)
|
||||
|
Reference in New Issue
Block a user