Merge pull request #1035 from whummer/fix/py2-s3-names-unicode
Allow non-ascii characters in request URLs
This commit is contained in:
commit
38dfcca269
@ -3,6 +3,7 @@ import json
|
||||
import re
|
||||
import sys
|
||||
import argparse
|
||||
import six
|
||||
|
||||
from six.moves.urllib.parse import urlencode
|
||||
|
||||
@ -47,6 +48,13 @@ class DomainDispatcherApplication(object):
|
||||
|
||||
def get_application(self, environ):
|
||||
path_info = environ.get('PATH_INFO', '')
|
||||
|
||||
# The URL path might contain non-ASCII text, for instance unicode S3 bucket names
|
||||
if six.PY2 and isinstance(path_info, str):
|
||||
path_info = six.u(path_info)
|
||||
if six.PY3 and isinstance(path_info, six.binary_type):
|
||||
path_info = path_info.decode('utf-8')
|
||||
|
||||
if path_info.startswith("/moto-api") or path_info == "/favicon.ico":
|
||||
host = "moto_api"
|
||||
elif path_info.startswith("/latest/meta-data/"):
|
||||
|
@ -1,3 +1,5 @@
|
||||
# coding=utf-8
|
||||
|
||||
from __future__ import unicode_literals
|
||||
import sure # noqa
|
||||
|
||||
@ -78,3 +80,18 @@ def test_s3_server_post_without_content_length():
|
||||
|
||||
res = test_client.post('/', "https://tester.localhost:5000/", environ_overrides={'CONTENT_LENGTH': ''})
|
||||
res.status_code.should.equal(411)
|
||||
|
||||
|
||||
def test_s3_server_post_unicode_bucket_key():
|
||||
# Make sure that we can deal with non-ascii characters in request URLs (e.g., S3 object names)
|
||||
dispatcher = server.DomainDispatcherApplication(server.create_backend_app)
|
||||
backend_app = dispatcher.get_application({
|
||||
'HTTP_HOST': 's3.amazonaws.com',
|
||||
'PATH_INFO': '/test-bucket/test-object-てすと'
|
||||
})
|
||||
assert backend_app
|
||||
backend_app = dispatcher.get_application({
|
||||
'HTTP_HOST': 's3.amazonaws.com',
|
||||
'PATH_INFO': '/test-bucket/test-object-てすと'.encode('utf-8')
|
||||
})
|
||||
assert backend_app
|
||||
|
Loading…
Reference in New Issue
Block a user