fix wrong encoding header from server

This commit is contained in:
Rotzbua 2021-11-11 00:53:29 +01:00 committed by Florian Festi
parent 8d30892d23
commit d43d44bf66
1 changed files with 7 additions and 2 deletions

View File

@ -417,9 +417,14 @@ class BServer:
type_, encoding = mimetypes.guess_type(filename)
if encoding is None:
encoding = "utf8"
encoding = "utf-8"
start_response("200 OK", [('Content-type', "%s; charset=%s" % (type_, encoding))])
# Images do not have charset. Just bytes. Except text based svg.
# Todo: fallback if type_ is None?
if type_ is not None and "image" in type_ and type_ != "image/svg+xml":
start_response("200 OK", [('Content-type', "%s" % type_)])
else:
start_response("200 OK", [('Content-type', "%s; charset=%s" % (type_, encoding))])
f = open(path, 'rb')
return environ['wsgi.file_wrapper'](f, 512*1024)