mirror of
https://github.com/frappe/gunicorn.git
synced 2026-01-14 11:09:11 +08:00
optimize a little bit headers parsing
This commit is contained in:
parent
9b4ab138fd
commit
d1858d2284
@ -36,15 +36,7 @@ class Message(object):
|
|||||||
headers = []
|
headers = []
|
||||||
|
|
||||||
# Split lines on \r\n keeping the \r\n on each line
|
# Split lines on \r\n keeping the \r\n on each line
|
||||||
lines = []
|
lines = [line + "\r\n" for line in data.split("\r\n")]
|
||||||
while len(data):
|
|
||||||
pos = data.find("\r\n")
|
|
||||||
if pos < 0:
|
|
||||||
lines.append(data)
|
|
||||||
data = ""
|
|
||||||
else:
|
|
||||||
lines.append(data[:pos+2])
|
|
||||||
data = data[pos+2:]
|
|
||||||
|
|
||||||
# Parse headers into key/value pairs paying attention
|
# Parse headers into key/value pairs paying attention
|
||||||
# to continuation lines.
|
# to continuation lines.
|
||||||
@ -139,19 +131,27 @@ class Request(Message):
|
|||||||
buf.truncate(0)
|
buf.truncate(0)
|
||||||
buf.write(rest)
|
buf.write(rest)
|
||||||
|
|
||||||
|
|
||||||
# Headers
|
# Headers
|
||||||
|
pos = 0
|
||||||
idx = buf.getvalue().find("\r\n\r\n")
|
idx = buf.getvalue().find("\r\n\r\n")
|
||||||
|
|
||||||
done = buf.getvalue()[:2] == "\r\n"
|
done = buf.getvalue()[:2] == "\r\n"
|
||||||
while idx < 0 and not done:
|
while idx < 0 and not done:
|
||||||
|
pos = buf.tell() - 4
|
||||||
self.get_data(unreader, buf)
|
self.get_data(unreader, buf)
|
||||||
idx = buf.getvalue().find("\r\n\r\n")
|
idx = buf.getvalue()[pos:].find("\r\n\r\n")
|
||||||
done = buf.getvalue()[:2] == "\r\n"
|
done = buf.getvalue()[:2] == "\r\n"
|
||||||
|
|
||||||
if done:
|
if done:
|
||||||
self.unreader.unread(buf.getvalue()[2:])
|
self.unreader.unread(buf.getvalue()[2:])
|
||||||
return ""
|
return ""
|
||||||
self.headers = self.parse_headers(buf.getvalue()[:idx])
|
|
||||||
|
|
||||||
ret = buf.getvalue()[idx+4:]
|
end = pos + idx
|
||||||
|
|
||||||
|
self.headers = self.parse_headers(buf.getvalue()[:end])
|
||||||
|
|
||||||
|
ret = buf.getvalue()[end+4:]
|
||||||
buf.truncate(0)
|
buf.truncate(0)
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user