Merge "Accept URL-encoded x-amz-copy-source headers"

This commit is contained in:
Jenkins 2015-12-16 05:44:57 +00:00 committed by Gerrit Code Review
commit 77cc55b41f
2 changed files with 14 additions and 3 deletions

View File

@ -15,7 +15,7 @@
import re
import md5
from urllib import quote
from urllib import quote, unquote
import base64
import email.utils
import datetime
@ -325,7 +325,7 @@ class Request(swob.Request):
check_copy_source checks the copy source existence
"""
if 'X-Amz-Copy-Source' in self.headers:
src_path = self.headers['X-Amz-Copy-Source']
src_path = unquote(self.headers['X-Amz-Copy-Source'])
src_path = src_path if src_path.startswith('/') else \
('/' + src_path)
src_bucket, src_obj = split_path(src_path, 0, 2, True)

View File

@ -21,6 +21,7 @@ from time import mktime
from multifile import MultiFile
from cStringIO import StringIO
from hashlib import md5
from urllib import quote
from swift3.test.functional.s3_test_client import Connection
from swift3.test.functional.utils import get_error_code,\
@ -43,7 +44,7 @@ class TestSwift3Object(Swift3FunctionalTestCase):
self.assertCommonResponseHeaders(headers, etag)
def test_object(self):
obj = 'object'
obj = 'object name with %-sign'
content = 'abc123'
etag = md5(content).hexdigest()
@ -67,6 +68,16 @@ class TestSwift3Object(Swift3FunctionalTestCase):
headers=headers)
self.assertEquals(status, 200)
# PUT Object Copy with URL-encoded Source
dst_bucket = 'dst-bucket'
dst_obj = 'dst_obj'
self.conn.make_request('PUT', dst_bucket)
headers = {'x-amz-copy-source': quote('/%s/%s' % (self.bucket, obj))}
status, headers, body = \
self.conn.make_request('PUT', dst_bucket, dst_obj,
headers=headers)
self.assertEquals(status, 200)
self.assertCommonResponseHeaders(headers)
self.assertEquals(headers['content-length'], str(len(body)))