[Zope3-checkins] 
	SVN: Zope3/branches/Zope-3.1/src/zope/publisher/http.py
	use the new MIME content-type parser to check if a charset
	needs to be
    Fred L. Drake, Jr. 
    fdrake at gmail.com
       
    Mon Aug  1 11:13:09 EDT 2005
    
    
  
Log message for revision 37624:
  use the new MIME content-type parser to check if a charset needs to be
  added and to perform the add properly
  (backported from trunk revision 37619)
  
Changed:
  U   Zope3/branches/Zope-3.1/src/zope/publisher/http.py
-=-
Modified: Zope3/branches/Zope-3.1/src/zope/publisher/http.py
===================================================================
--- Zope3/branches/Zope-3.1/src/zope/publisher/http.py	2005-08-01 15:11:32 UTC (rev 37623)
+++ Zope3/branches/Zope-3.1/src/zope/publisher/http.py	2005-08-01 15:13:08 UTC (rev 37624)
@@ -23,6 +23,7 @@
 
 from zope.interface import implements
 
+from zope.publisher import contenttype
 from zope.publisher.interfaces.http import IHTTPCredentials
 from zope.publisher.interfaces.http import IHTTPRequest
 from zope.publisher.interfaces.http import IHTTPApplicationRequest
@@ -715,11 +716,16 @@
         self._charset = charset
 
     def _updateContentType(self):
-        if self._charset is not None:
+        if self._charset:
             ctype = self.getHeader('content-type', '')
-            if ctype.startswith("text") and "charset" not in ctype:
-                self.setHeader('content-type',
-                        ctype + ";charset=" + self._charset)
+            if ctype.lower().startswith('text'):
+                ctinfo = contenttype.parseOrdered(ctype)
+                for param, value in ctinfo[2]:
+                    if param == "charset":
+                        break
+                else:
+                    ctinfo[2].append(("charset", self._charset))
+                    self.setHeader('content-type', contenttype.join(ctinfo))
 
     def setCharsetUsingRequest(self, request):
         'See IHTTPResponse'
    
    
More information about the Zope3-Checkins
mailing list