diff --git a/src/calibre/srv/http.py b/src/calibre/srv/http.py index a2e50658cb..7f90ae55f8 100644 --- a/src/calibre/srv/http.py +++ b/src/calibre/srv/http.py @@ -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)) diff --git a/src/calibre/srv/respond.py b/src/calibre/srv/respond.py index 9c16879d3f..d48ea94e9a 100644 --- a/src/calibre/srv/respond.py +++ b/src/calibre/srv/respond.py @@ -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