[Zope3-checkins] SVN: Zope3/trunk/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 10:53:50 EDT 2005
Log message for revision 37619:
use the new MIME content-type parser to check if a charset needs to be
added and to perform the add properly
Changed:
U Zope3/trunk/src/zope/publisher/http.py
-=-
Modified: Zope3/trunk/src/zope/publisher/http.py
===================================================================
--- Zope3/trunk/src/zope/publisher/http.py 2005-08-01 14:51:53 UTC (rev 37618)
+++ Zope3/trunk/src/zope/publisher/http.py 2005-08-01 14:53:50 UTC (rev 37619)
@@ -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