Skip to content

Commit 7168d21

Browse files
murlockfvennetier
authored andcommitted
copy: fix autocontainer and utf8
Fastcopy was not compatible with Autocontainer, new header was unprocessed. When a copy is done with UTF-8 characters, copy failed with double quote issue.
1 parent a529c3d commit 7168d21

File tree

2 files changed

+15
-7
lines changed

2 files changed

+15
-7
lines changed

oioswift/common/middleware/autocontainerbase.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,8 @@ def _alternatives(self, account, container, obj):
9393
@staticmethod
9494
def is_copy(env):
9595
"""Tell if `env` represents an object copy operation."""
96-
return env['REQUEST_METHOD'] == 'PUT' and 'HTTP_X_COPY_FROM' in env
96+
return (env['REQUEST_METHOD'] == 'PUT' and
97+
('HTTP_X_COPY_FROM' in env or 'HTTP_OIO_COPY_FROM' in env))
9798

9899
@staticmethod
99100
def _save_response(env, status, headers, exc_info=None):
@@ -159,15 +160,23 @@ def _call_copy(self, env, start_response):
159160
return self.app(env, start_response)
160161
env['PATH_INFO'] = "/v1/%s/%s/%s" % (account, container, obj)
161162

163+
for hdr in ("HTTP_OIO_COPY_FROM", "HTTP_X_COPY_FROM"):
164+
if hdr in env:
165+
from_value = env.get(hdr)
166+
from_header = hdr
167+
break
168+
else:
169+
raise HTTPBadRequest(body="Malformed copy-source header")
170+
162171
# HTTP_X_COPY_FROM_ACCOUNT will just pass through
163172
if self.account_first:
164-
src_path = "/fake_account" + env['HTTP_X_COPY_FROM']
173+
src_path = "/fake_account" + from_value
165174
else:
166-
src_path = env['HTTP_X_COPY_FROM']
175+
src_path = from_value
167176

168177
def modify_copy_from(orig_env, alternative):
169178
env_ = orig_env.copy()
170-
env_['HTTP_X_COPY_FROM'] = "/%s/%s" % (
179+
env_[from_header] = "/%s/%s" % (
171180
quote_plus(alternative[1]), alternative[2])
172181
return env_
173182

oioswift/common/middleware/copy.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -261,9 +261,8 @@ def __call__(self, env, start_response):
261261
# FIXME: handle COPY method (with Destination-* headers)
262262
if self.fast_copy_allowed(req):
263263
self.logger.debug("COPY: fast copy allowed")
264-
# FIXME(FVE): we may use req.environ instead of headers
265-
req.headers['Oio-Copy-From'] = req.headers.get('X-Copy-From')
266-
del req.headers['X-Copy-From']
264+
env['HTTP_OIO_COPY_FROM'] = unquote(env['HTTP_X_COPY_FROM'])
265+
del env['HTTP_X_COPY_FROM']
267266
return self.app(env, start_response)
268267

269268
try:

0 commit comments

Comments
 (0)