From 7168d219b21b2f7528b22da6d37169c252470494 Mon Sep 17 00:00:00 2001 From: Michael Bonfils Date: Wed, 18 Apr 2018 15:07:31 +0200 Subject: [PATCH] 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. --- oioswift/common/middleware/autocontainerbase.py | 17 +++++++++++++---- oioswift/common/middleware/copy.py | 5 ++--- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/oioswift/common/middleware/autocontainerbase.py b/oioswift/common/middleware/autocontainerbase.py index 6131725b..41179fdd 100644 --- a/oioswift/common/middleware/autocontainerbase.py +++ b/oioswift/common/middleware/autocontainerbase.py @@ -93,7 +93,8 @@ def _alternatives(self, account, container, obj): @staticmethod def is_copy(env): """Tell if `env` represents an object copy operation.""" - return env['REQUEST_METHOD'] == 'PUT' and 'HTTP_X_COPY_FROM' in env + return (env['REQUEST_METHOD'] == 'PUT' and + ('HTTP_X_COPY_FROM' in env or 'HTTP_OIO_COPY_FROM' in env)) @staticmethod def _save_response(env, status, headers, exc_info=None): @@ -159,15 +160,23 @@ def _call_copy(self, env, start_response): return self.app(env, start_response) env['PATH_INFO'] = "/v1/%s/%s/%s" % (account, container, obj) + for hdr in ("HTTP_OIO_COPY_FROM", "HTTP_X_COPY_FROM"): + if hdr in env: + from_value = env.get(hdr) + from_header = hdr + break + else: + raise HTTPBadRequest(body="Malformed copy-source header") + # HTTP_X_COPY_FROM_ACCOUNT will just pass through if self.account_first: - src_path = "/fake_account" + env['HTTP_X_COPY_FROM'] + src_path = "/fake_account" + from_value else: - src_path = env['HTTP_X_COPY_FROM'] + src_path = from_value def modify_copy_from(orig_env, alternative): env_ = orig_env.copy() - env_['HTTP_X_COPY_FROM'] = "/%s/%s" % ( + env_[from_header] = "/%s/%s" % ( quote_plus(alternative[1]), alternative[2]) return env_ diff --git a/oioswift/common/middleware/copy.py b/oioswift/common/middleware/copy.py index 96d2eebf..749f9399 100644 --- a/oioswift/common/middleware/copy.py +++ b/oioswift/common/middleware/copy.py @@ -261,9 +261,8 @@ def __call__(self, env, start_response): # FIXME: handle COPY method (with Destination-* headers) if self.fast_copy_allowed(req): self.logger.debug("COPY: fast copy allowed") - # FIXME(FVE): we may use req.environ instead of headers - req.headers['Oio-Copy-From'] = req.headers.get('X-Copy-From') - del req.headers['X-Copy-From'] + env['HTTP_OIO_COPY_FROM'] = unquote(env['HTTP_X_COPY_FROM']) + del env['HTTP_X_COPY_FROM'] return self.app(env, start_response) try: