Skip to content

Commit

Permalink
copy: fix autocontainer and utf8
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
murlock authored and fvennetier committed Apr 18, 2018
1 parent a529c3d commit 7168d21
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
17 changes: 13 additions & 4 deletions oioswift/common/middleware/autocontainerbase.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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_

Expand Down
5 changes: 2 additions & 3 deletions oioswift/common/middleware/copy.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 7168d21

Please sign in to comment.