fix bucket creation. REQUEST_METHOD PUT not translated to POST if request has X_AMZ_ACL header

This commit is contained in:
Victor Rodionov 2012-10-26 18:26:49 +04:00 committed by FUJITA Tomonori
parent 8883a4ef63
commit 7eb4025eb7

View File

@ -483,16 +483,16 @@ class BucketController(WSGIContext):
""" """
Handle PUT Bucket request Handle PUT Bucket request
""" """
for key, value in env.items(): if 'HTTP_X_AMZ_ACL' in env:
if key == "HTTP_X_AMZ_ACL": amz_acl = env['HTTP_X_AMZ_ACL']
# Translate the Amazon ACL to something that can be # Translate the Amazon ACL to something that can be
# implemented in Swift, 501 otherwise. Swift uses POST # implemented in Swift, 501 otherwise. Swift uses POST
# for ACLs, whereas S3 uses PUT. # for ACLs, whereas S3 uses PUT.
del env[key] del env['HTTP_X_AMZ_ACL']
if 'QUERY_STRING' in env: if 'QUERY_STRING' in env:
del env['QUERY_STRING'] del env['QUERY_STRING']
translated_acl = swift_acl_translate(value) translated_acl = swift_acl_translate(amz_acl)
if translated_acl == 'Unsupported': if translated_acl == 'Unsupported':
return get_err_response('Unsupported') return get_err_response('Unsupported')
elif translated_acl == 'InvalidArgument': elif translated_acl == 'InvalidArgument':
@ -500,16 +500,20 @@ class BucketController(WSGIContext):
for header, acl in translated_acl: for header, acl in translated_acl:
env[header] = acl env[header] = acl
env['REQUEST_METHOD'] = 'POST'
if key == "CONTENT_LENGTH" and (value.isdigit() is False or if 'CONTENT_LENGTH' in env:
value < 0): content_length = env['CONTENT_LENGTH']
return get_err_response("InvalidArgument") try:
if key == "QUERY_STRING": content_length = int(content_length)
args = dict(urlparse.parse_qsl(value, 1)) except (ValueError, TypeError):
if 'acl' in args and 'CONTENT_LENGTH' in env \ get_err_response('InvalidArgument')
and int(env['CONTENT_LENGTH']) > 0 and \ if content_length < 0:
'HTTP_X_AMZ_ACL' not in env: get_err_response('InvalidArgument')
# We very likely have an XML-based ACL request
if 'QUERY_STRING' in env:
args = dict(urlparse.parse_qsl(env['QUERY_STRING'], 1))
if 'acl' in args:
# We very likely have an XML-based ACL request.
body = env['wsgi.input'].readline().decode() body = env['wsgi.input'].readline().decode()
translated_acl = swift_acl_translate(body, xml=True) translated_acl = swift_acl_translate(body, xml=True)
if translated_acl == 'Unsupported': if translated_acl == 'Unsupported':