[Zope-CMF] Fwd: [CMF] 281/ 1 Request "FSFile content_type weakness"
Jens Vagelpohl
jens at dataflake.org
Sun Sep 5 07:13:22 EDT 2004
> Uploaded: "FSFile.pat"
> - http://zope.org/Collectors/CMF/281/FSFile.pat/view
> The way the content_type is detected in CMFCore.FSFile prevents
> content_type to be explicitly specified inside a .metadata file for
> the resource since any content_type value coming from the .metadata
> file is disregarded. This small patch will, as a last resort, use a
> content_type specification from the .metadata file *if* it is obvious
> that the normal content_type detection has failed, meaning it returned
> "application/octet-stream".
>
> Specific use case for this change: I am trying to store a favicon.ico
> file on the file system. Without the patch it will always have
> "application/octet-stream" and that makes some browsers unhappy.
Any objections to me merging this patch:
************************************************************
? FSFile.pat
Index: CMFCore/FSFile.py
===================================================================
RCS file: /cvs-repository/Products/CMFCore/FSFile.py,v
retrieving revision 1.11
diff -u -r1.11 FSFile.py
--- CMFCore/FSFile.py 12 Aug 2004 15:07:39 -0000 1.11
+++ CMFCore/FSFile.py 5 Sep 2004 11:00:45 -0000
@@ -66,6 +66,16 @@
if type(body) is not type(''): body=body.data
content_type, enc=guess_content_type(
getattr(file, 'filename',id), body, content_type)
+
+ # Be more intelligent when the meager content type
detection fails
+ # This check allows a content_type value from a .metadata
file
+ # to be considered as last resort.
+ bad_type = 'application/octet-stream'
+ if ( content_type.lower() == bad_type and
+ getattr(self, 'content_type', '') and
+ self.content_type not in ('unknown/unknown',
bad_type)):
+ content_type = self.content_type
+
return content_type
def _readFile(self, reparse):
******************************************
jens
More information about the Zope-CMF
mailing list