mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-08 10:44:09 -04:00
Ensure text/* content types always include a charset declaration
This commit is contained in:
parent
03347846d9
commit
439ddab5e5
@ -586,6 +586,10 @@ class HTTPPair(object):
|
||||
if not self.close_connection:
|
||||
self.outheaders.set('Connection', 'Keep-Alive')
|
||||
|
||||
ct = self.outheaders.get('Content-Type', '')
|
||||
if ct.startswith('text/') and 'charset=' not in ct:
|
||||
self.outheaders.set('Content-Type', ct + '; charset=UTF-8')
|
||||
|
||||
buf = [HTTP11 + (' %d ' % self.status_code) + httplib.responses[self.status_code]]
|
||||
for header, value in sorted(self.outheaders.iteritems(), key=itemgetter(0)):
|
||||
buf.append('%s: %s' % (header, value))
|
||||
|
@ -210,10 +210,9 @@ class DynamicOutput(object):
|
||||
self.data = output
|
||||
else:
|
||||
self.data = output.encode('utf-8')
|
||||
ct = outheaders.get('Content-Type', 'text/plain')
|
||||
if 'charset=' not in ct:
|
||||
ct += '; charset=UTF-8'
|
||||
outheaders.set('Content-Type', ct, replace_all=True)
|
||||
ct = outheaders.get('Content-Type')
|
||||
if not ct:
|
||||
outheaders.set('Content-Type', 'text/plain; charset=UTF-8', replace_all=True)
|
||||
self.content_length = len(self.data)
|
||||
self.etag = None
|
||||
self.accept_ranges = False
|
||||
|
Loading…
x
Reference in New Issue
Block a user