mirror of
https://github.com/frappe/gunicorn.git
synced 2026-01-14 11:09:11 +08:00
don't return utf8 header in example
Since the updated RFC 7230 implys that new Headers Key and Value should be sent as USASCII only don't try to test utf8 headers in examples. We now only encode them to ascii. Gunicorn will fail if it's unable to encode them letting the responsability to the application to correctly encode the response. (we are just a gateway). While i'm here simplify the code to not create an extra function only used at one place. NOTE: if anyone come to a better solution, i am happy to revisit it on the next release. fix #1151
This commit is contained in:
parent
6b92575e00
commit
5f4ebd2eb2
@ -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])
|
||||
|
||||
@ -320,7 +320,7 @@ class Response(object):
|
||||
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):
|
||||
|
||||
@ -25,7 +25,6 @@ from gunicorn.errors import AppImportError
|
||||
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):
|
||||
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("utf-8")
|
||||
|
||||
|
||||
def to_latin1(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("latin-1")
|
||||
|
||||
return value.encode(encoding)
|
||||
|
||||
def warn(msg):
|
||||
print("!!!", file=sys.stderr)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user