# HG changeset patch # User Thierry Florac # Date 1496912473 -7200 # Node ID b1f7b1173aa3f3cf84147a64e7ae7e64f8f48cd2 # Parent 73dcb9ffe391a95b3e4249be4d95a0c9f68ca353 Added check on file content type diff -r 73dcb9ffe391 -r b1f7b1173aa3 src/pyams_file/views/file.py --- a/src/pyams_file/views/file.py Tue Jun 06 17:31:19 2017 +0200 +++ b/src/pyams_file/views/file.py Thu Jun 08 11:01:13 2017 +0200 @@ -33,20 +33,26 @@ """Default file view""" context = request.context + # set content type + content_type = context.content_type + if isinstance(content_type, bytes): + content_type = content_type.decode('utf-8') + # check for last modification date modified = IZopeDublinCore(context).modified if_modified_since = request.if_modified_since if if_modified_since and (int(modified.timestamp()) <= int(if_modified_since.timestamp())): - return Response(content_type=context.content_type.decode('utf-8'), + return Response(content_type=content_type, status=NOT_MODIFIED) - response = Response(content_type=context.content_type.decode('utf-8'), + response = Response(content_type=content_type, last_modified=modified) body_file = context.get_blob(mode='c') if request.params.get('download') is not None: response.content_disposition = 'attachment; filename="{0}"'.format(context.filename) + # check for range request if request.range is not None: body = body_file.read() body_length = len(body)