Added check on file content type
authorThierry Florac <thierry.florac@onf.fr>
Thu, 08 Jun 2017 11:01:13 +0200
changeset 38 b1f7b1173aa3
parent 37 73dcb9ffe391
child 39 a9ef7fc88d49
Added check on file content type
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)