Skip to content

Commit

Permalink
Merge 7359ace into a8e06f2
Browse files Browse the repository at this point in the history
  • Loading branch information
NguyenDucThanhTam committed Jan 4, 2018
2 parents a8e06f2 + 7359ace commit 0975b72
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 6 deletions.
2 changes: 1 addition & 1 deletion requirements.txt
Expand Up @@ -5,7 +5,7 @@ boto3>=1.4.7
docutils>=0.12
durationpy==0.5
future==0.16.0
futures==3.1.1
futures==3.2.0
hjson==3.0.1
jmespath==0.9.3
kappa==0.6.0
Expand Down
4 changes: 2 additions & 2 deletions test_requirements.txt
@@ -1,8 +1,8 @@
coveralls>=1.1
coverage>=4.3.1
Django>=1.10.5
Django>=1.10.5, <2.0
Flask>=0.12
mock>=2.0.0
nose>=1.3.7
nose-timer>=0.6.0
placebo>=0.8.1
placebo>=0.8.1
15 changes: 15 additions & 0 deletions tests/tests.py
Expand Up @@ -529,6 +529,21 @@ def test_wsgi_path_info_unquoted(self):
request = create_wsgi_request(event, trailing_slash=True)
self.assertEqual("/path:1", request['PATH_INFO'])

def test_wsgi_latin1(self):
event = {
"body": {},
"headers": {},
"pathParameters": {},
"path": '/path/%E4%BB%8A%E6%97%A5%E3%81%AF',
"httpMethod": "GET",
"queryStringParameters": {"a": "%E4%BB%8A%E6%97%A5%E3%81%AF"},
"requestContext": {}
}
request = create_wsgi_request(event, script_name="%E4%BB%8A%E6%97%A5%E3%81%AF")
# verify that the path, query params and script name can be encoded in iso-8859-1
request['PATH_INFO'].encode('iso-8859-1')
request['QUERY_STRING'].encode('iso-8859-1')
request['SCRIPT_NAME'].encode('iso-8859-1')

def test_wsgi_logging(self):
# event = {
Expand Down
14 changes: 11 additions & 3 deletions zappa/wsgi.py
Expand Up @@ -102,11 +102,11 @@ def create_wsgi_request(event_info,
remote_addr = '127.0.0.1'

environ = {
'PATH_INFO': path,
'QUERY_STRING': query_string,
'PATH_INFO': get_wsgi_string(path),
'QUERY_STRING': get_wsgi_string(query_string),
'REMOTE_ADDR': remote_addr,
'REQUEST_METHOD': method,
'SCRIPT_NAME': str(script_name) if script_name else '',
'SCRIPT_NAME': get_wsgi_string(str(script_name)) if script_name else '',
'SERVER_NAME': str(server_name),
'SERVER_PORT': headers.get('X-Forwarded-Port', '80'),
'SERVER_PROTOCOL': str('HTTP/1.1'),
Expand Down Expand Up @@ -177,3 +177,11 @@ def common_log(environ, response, response_time=None):
logger.info(log_entry)

return log_entry


# Related: https://github.com/Miserlou/Zappa/issues/1199
def get_wsgi_string(string, encoding='utf-8'):
"""
Returns wsgi-compatible string
"""
return string.encode(encoding).decode('iso-8859-1')

0 comments on commit 0975b72

Please sign in to comment.