diff --git a/examples/test.py b/examples/test.py index 84f9102c1c..476fd62ff7 100644 --- a/examples/test.py +++ b/examples/test.py @@ -21,7 +21,7 @@ def app(environ, start_response): ('Content-type', 'text/plain'), ('Content-Length', str(len(data))), ('X-Gunicorn-Version', __version__), - ("Test", "test тест"), + #("Test", "test тест"), ] start_response(status, response_headers) return iter([data]) diff --git a/gunicorn/http/wsgi.py b/gunicorn/http/wsgi.py index 6804eb80d8..64e547e1e6 100644 --- a/gunicorn/http/wsgi.py +++ b/gunicorn/http/wsgi.py @@ -320,7 +320,7 @@ def send_headers(self): tosend.extend(["%s: %s\r\n" % (k, v) for k, v in self.headers]) header_str = "%s\r\n" % "".join(tosend) - util.write(self.sock, util.to_latin1(header_str)) + util.write(self.sock, util.to_bytestring(header_str, "ascii")) self.headers_sent = True def write(self, arg): diff --git a/gunicorn/util.py b/gunicorn/util.py index ad99fb9de3..49d08690a4 100644 --- a/gunicorn/util.py +++ b/gunicorn/util.py @@ -25,7 +25,6 @@ from gunicorn.six import text_type from gunicorn.workers import SUPPORTED_WORKERS - MAXFD = 1024 REDIRECT_TO = getattr(os, 'devnull', '/dev/null') @@ -498,23 +497,14 @@ def check_is_writeable(path): f.close() -def to_bytestring(value): - """Converts a string argument to a byte string""" - if isinstance(value, bytes): - return value - if not isinstance(value, text_type): - raise TypeError('%r is not a string' % value) - return value.encode("utf-8") - - -def to_latin1(value): +def to_bytestring(value, encoding="utf8"): """Converts a string argument to a byte string""" if isinstance(value, bytes): return value if not isinstance(value, text_type): raise TypeError('%r is not a string' % value) - return value.encode("latin-1") + return value.encode(encoding) def warn(msg): print("!!!", file=sys.stderr)