Fix s3bucket_path (#784)

* check HTTP header for IPv4 or IPv6 addresses and default to path based S3

* improved IPv4 and IPv6 checking with optional ports

* typo

* subdomain bucket creation with trailing '/' did not work

* Use regex for Host field check to determine IPv4/IPv6

* add testcases for trailing slash, IPv4 and IPv6
This commit is contained in:
mfranke 2016-12-04 00:15:24 +01:00 committed by Steve Pulec
commit 5dc8e59fab
3 changed files with 62 additions and 13 deletions

View file

@ -7,13 +7,23 @@ url_bases = [
"https?://(?P<bucket_name>[a-zA-Z0-9\-_.]*)\.?s3(.*).amazonaws.com"
]
def ambiguous_response1(*args, **kwargs):
return S3ResponseInstance.ambiguous_response(*args, **kwargs)
def ambiguous_response2(*args, **kwargs):
return S3ResponseInstance.ambiguous_response(*args, **kwargs)
url_paths = {
# subdomain bucket
'{0}/$': S3ResponseInstance.bucket_response,
# subdomain key of path-based bucket
'{0}/(?P<key_or_bucket_name>[^/]+)/?$': S3ResponseInstance.ambiguous_response,
'{0}/(?P<key_or_bucket_name>[^/]+)$': ambiguous_response1,
# subdomain key of path-based bucket
'{0}/(?P<key_or_bucket_name>[^/]+)/$': ambiguous_response2,
# path-based bucket + key
'{0}/(?P<bucket_name_path>[^/]+)/(?P<key_name>.+)': S3ResponseInstance.key_response,
}