mirror of
https://github.com/frappe/gunicorn.git
synced 2026-01-14 11:09:11 +08:00
fix header encoding
This commit is contained in:
parent
f240b78fd3
commit
91e7d138dc
@ -18,7 +18,8 @@ def app(environ, start_response):
|
|||||||
response_headers = [
|
response_headers = [
|
||||||
('Content-type','text/plain'),
|
('Content-type','text/plain'),
|
||||||
('Content-Length', str(len(data))),
|
('Content-Length', str(len(data))),
|
||||||
('X-Gunicorn-Version', __version__)
|
('X-Gunicorn-Version', __version__),
|
||||||
|
("Test", "test тест"),
|
||||||
]
|
]
|
||||||
start_response(status, response_headers)
|
start_response(status, response_headers)
|
||||||
return iter([data])
|
return iter([data])
|
||||||
|
|||||||
@ -210,6 +210,7 @@ class Response(object):
|
|||||||
def process_headers(self, headers):
|
def process_headers(self, headers):
|
||||||
for name, value in headers:
|
for name, value in headers:
|
||||||
assert isinstance(name, string_types), "%r is not a string" % name
|
assert isinstance(name, string_types), "%r is not a string" % name
|
||||||
|
|
||||||
lname = name.lower().strip()
|
lname = name.lower().strip()
|
||||||
if lname == "content-length":
|
if lname == "content-length":
|
||||||
self.response_length = int(value)
|
self.response_length = int(value)
|
||||||
@ -220,11 +221,11 @@ class Response(object):
|
|||||||
self.upgrade = True
|
self.upgrade = True
|
||||||
elif lname == "upgrade":
|
elif lname == "upgrade":
|
||||||
if value.lower().strip() == "websocket":
|
if value.lower().strip() == "websocket":
|
||||||
self.headers.append((name.strip(), str(value).strip()))
|
self.headers.append((name.strip(), value.strip()))
|
||||||
|
|
||||||
# ignore hopbyhop headers
|
# ignore hopbyhop headers
|
||||||
continue
|
continue
|
||||||
self.headers.append((name.strip(), str(value).strip()))
|
self.headers.append((name.strip(), str(value.strip())))
|
||||||
|
|
||||||
|
|
||||||
def is_chunked(self):
|
def is_chunked(self):
|
||||||
@ -265,10 +266,10 @@ class Response(object):
|
|||||||
if self.headers_sent:
|
if self.headers_sent:
|
||||||
return
|
return
|
||||||
tosend = self.default_headers()
|
tosend = self.default_headers()
|
||||||
tosend.extend(["%s: %s\r\n" % (n, v) for n, v in self.headers])
|
tosend.extend(["%s: %s\r\n" % (k,v) for k, v in self.headers])
|
||||||
|
|
||||||
header_str = "%s\r\n" % "".join(tosend)
|
header_str = "%s\r\n" % "".join(tosend)
|
||||||
util.write(self.sock, header_str.encode('latin1'))
|
util.write(self.sock, util.to_bytestring(header_str))
|
||||||
self.headers_sent = True
|
self.headers_sent = True
|
||||||
|
|
||||||
def write(self, arg):
|
def write(self, arg):
|
||||||
|
|||||||
@ -348,3 +348,10 @@ def check_is_writeable(path):
|
|||||||
except IOError as e:
|
except IOError as e:
|
||||||
raise RuntimeError("Error: '%s' isn't writable [%r]" % (path, e))
|
raise RuntimeError("Error: '%s' isn't writable [%r]" % (path, e))
|
||||||
f.close()
|
f.close()
|
||||||
|
|
||||||
|
def to_bytestring(value):
|
||||||
|
"""Converts a string argument to a byte string"""
|
||||||
|
if isinstance(value, bytes):
|
||||||
|
return value
|
||||||
|
assert isinstance(value, text_type)
|
||||||
|
return value.encode("utf-8")
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user