From f3c8c36cddbf1801443af431bc7db2e6d844eaed Mon Sep 17 00:00:00 2001 From: Luis Pabon Date: Tue, 26 Nov 2013 20:21:10 -0500 Subject: Return BadRequest on X-Delete-At/After headers Gluster-swift does not support X-Delete-After or X-Delete-At headers. The code needs to inform the caller with a 400-BadRequest if they use these headers. Change-Id: Ic9d3a1646c0d26bb0204245efce4501f7479fee6 Signed-off-by: Luis Pabon Reviewed-on: http://review.gluster.org/6364 Reviewed-by: Chetan Risbud Reviewed-on: http://review.gluster.org/6444 --- gluster/swift/common/constraints.py | 39 ++++++++++++++++++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) (limited to 'gluster/swift/common/constraints.py') diff --git a/gluster/swift/common/constraints.py b/gluster/swift/common/constraints.py index 523277d..7681c49 100644 --- a/gluster/swift/common/constraints.py +++ b/gluster/swift/common/constraints.py @@ -23,6 +23,7 @@ import swift.common.ring as _ring from gluster.swift.common import Glusterfs, ring MAX_OBJECT_NAME_COMPONENT_LENGTH = 255 +UNSUPPORTED_HEADERS = ['x-delete-at', 'x-delete-after'] def set_object_name_component_length(len=None): @@ -54,8 +55,41 @@ def validate_obj_name_component(obj): return 'cannot be . or ..' return '' + +def validate_headers(req): + """ + Validate client header requests + :param req: Http request + """ + if not Glusterfs._ignore_unsupported_headers: + for unsupported_header in UNSUPPORTED_HEADERS: + if unsupported_header in req.headers: + return '%s headers are not supported' \ + % ','.join(UNSUPPORTED_HEADERS) + return '' + # Save the original check object creation __check_object_creation = swift.common.constraints.check_object_creation +__check_metadata = swift.common.constraints.check_metadata + + +def gluster_check_metadata(req, target_type, POST=True): + """ + :param req: HTTP request object + :param target_type: Value from POST passed to __check_metadata + :param POST: Only call __check_metadata on POST since Swift only + calls check_metadata on POSTs. + """ + ret = None + if POST: + ret = __check_metadata(req, target_type) + if ret is None: + bdy = validate_headers(req) + if bdy: + ret = HTTPBadRequest(body=bdy, + request=req, + content_type='text/plain') + return ret # Define our new one which invokes the original @@ -85,11 +119,14 @@ def gluster_check_object_creation(req, object_name): ret = HTTPBadRequest(body=bdy, request=req, content_type='text/plain') + if ret is None: + ret = gluster_check_metadata(req, 'object', POST=False) return ret -# Replace the original check object creation with ours +# Replace the original checks with ours swift.common.constraints.check_object_creation = gluster_check_object_creation +swift.common.constraints.check_metadata = gluster_check_metadata # Replace the original check mount with ours swift.common.constraints.check_mount = Glusterfs.mount -- cgit