Skip to content

Commit

Permalink
seems .splitlines() has bug use .split() instead #97
Browse files Browse the repository at this point in the history
  • Loading branch information
fafhrd91 committed Jul 8, 2014
1 parent a66b964 commit a6a179c
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 17 deletions.
2 changes: 1 addition & 1 deletion aiohttp/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This relies on each of the submodules having an __all__ variable.

__version__ = '0.9.0dev'
__version__ = '0.9.0dev2'


from .protocol import *
Expand Down
10 changes: 5 additions & 5 deletions aiohttp/protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def parse_headers(self, lines):
lines_idx = 1
line = lines[1]

while line not in ('\r\n', '\n'):
while line:
header_length = len(line)

# Parse initial header name : value pair.
Expand All @@ -78,7 +78,7 @@ def parse_headers(self, lines):
line = lines[lines_idx]

# consume continuation lines
continuation = line[0] in CONTINUATION
continuation = line and line[0] in CONTINUATION

if continuation:
value = [value]
Expand All @@ -93,7 +93,7 @@ def parse_headers(self, lines):
lines_idx += 1
line = lines[lines_idx]
continuation = line[0] in CONTINUATION
value = ''.join(value)
value = '\r\n'.join(value)
else:
if header_length > self.max_field_size:
raise errors.LineTooLong(
Expand Down Expand Up @@ -156,7 +156,7 @@ def __call__(self, out, buf):
raise errors.LineTooLong(exc.limit) from None

lines = raw_data.decode(
'ascii', 'surrogateescape').splitlines(True)
'ascii', 'surrogateescape').split('\r\n')

# request line
line = lines[0]
Expand Down Expand Up @@ -205,7 +205,7 @@ def __call__(self, out, buf):
raise errors.LineTooLong(exc.limit) from None

lines = raw_data.decode(
'ascii', 'surrogateescape').splitlines(True)
'ascii', 'surrogateescape').split('\r\n')

line = lines[0]
try:
Expand Down
22 changes: 11 additions & 11 deletions tests/test_http_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ def setUp(self):
self.parser = protocol.HttpParser(8190, 32768, 8190)

def test_parse_headers(self):
hdrs = ('', 'test: line\r\n', ' continue\r\n',
'test2: data\r\n', '\r\n')
hdrs = ('', 'test: line', ' continue',
'test2: data', '', '')

headers, close, compression = self.parser.parse_headers(hdrs)

Expand All @@ -31,8 +31,8 @@ def test_parse_headers(self):

def test_parse_headers_multi(self):
hdrs = ('',
'Set-Cookie: c1=cookie1\r\n',
'Set-Cookie: c2=cookie2\r\n', '\r\n')
'Set-Cookie: c1=cookie1',
'Set-Cookie: c2=cookie2', '')

headers, close, compression = self.parser.parse_headers(hdrs)

Expand All @@ -44,32 +44,32 @@ def test_parse_headers_multi(self):

def test_conn_close(self):
headers, close, compression = self.parser.parse_headers(
['', 'connection: close\r\n', '\r\n'])
['', 'connection: close', ''])
self.assertTrue(close)

def test_conn_keep_alive(self):
headers, close, compression = self.parser.parse_headers(
['', 'connection: keep-alive\r\n', '\r\n'])
['', 'connection: keep-alive', ''])
self.assertFalse(close)

def test_conn_other(self):
headers, close, compression = self.parser.parse_headers(
['', 'connection: test\r\n', '\r\n'])
['', 'connection: test', '', ''])
self.assertIsNone(close)

def test_compression_gzip(self):
headers, close, compression = self.parser.parse_headers(
['', 'content-encoding: gzip\r\n', '\r\n'])
['', 'content-encoding: gzip', '', ''])
self.assertEqual('gzip', compression)

def test_compression_deflate(self):
headers, close, compression = self.parser.parse_headers(
['', 'content-encoding: deflate\r\n', '\r\n'])
['', 'content-encoding: deflate', '', ''])
self.assertEqual('deflate', compression)

def test_compression_unknown(self):
headers, close, compression = self.parser.parse_headers(
['', 'content-encoding: compress\r\n', '\r\n'])
['', 'content-encoding: compress', '', ''])
self.assertIsNone(compression)

def test_max_field_size(self):
Expand Down Expand Up @@ -480,7 +480,7 @@ def test_http_response_parser_bad_version(self):
next(p)
with self.assertRaises(errors.BadStatusLine) as cm:
p.send(b'HT/11 200 Ok\r\n\r\n')
self.assertEqual('HT/11 200 Ok\r\n', cm.exception.args[0])
self.assertEqual('HT/11 200 Ok', cm.exception.args[0])

def test_http_response_parser_no_reason(self):
out = aiohttp.FlowControlDataQueue(self.stream)
Expand Down

0 comments on commit a6a179c

Please sign in to comment.