-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
do not use readline when reading the content of a part in the multipart reader #1535
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,6 +13,8 @@ | |
from aiohttp.helpers import parse_mimetype | ||
from aiohttp.multipart import (content_disposition_filename, | ||
parse_content_disposition) | ||
from aiohttp.streams import DEFAULT_LIMIT as stream_reader_default_limit | ||
from aiohttp.streams import StreamReader | ||
|
||
|
||
def run_in_loop(f): | ||
|
@@ -255,14 +257,13 @@ def test_read_chunk_properly_counts_read_bytes(self): | |
self.assertEqual(b'.' * size, result) | ||
self.assertTrue(obj.at_eof()) | ||
|
||
def test_read_does_reads_boundary(self): | ||
def test_read_does_not_read_boundary(self): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Well, actually test reads the boundary (: In previous case it just was placed into unread buffer. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not entirely sure, but i think it reads the boundary then put in back in the stream (with |
||
stream = Stream(b'Hello, world!\r\n--:') | ||
obj = aiohttp.multipart.BodyPartReader( | ||
self.boundary, {}, stream) | ||
result = yield from obj.read() | ||
self.assertEqual(b'Hello, world!', result) | ||
self.assertEqual(b'', (yield from stream.read())) | ||
self.assertEqual([b'--:'], list(obj._unread)) | ||
self.assertEqual(b'--:', (yield from stream.read())) | ||
|
||
def test_multiread(self): | ||
obj = aiohttp.multipart.BodyPartReader( | ||
|
@@ -474,8 +475,7 @@ def test_release(self): | |
self.boundary, {}, stream) | ||
yield from obj.release() | ||
self.assertTrue(obj.at_eof()) | ||
self.assertEqual(b'\r\nworld!\r\n--:--', stream.content.read()) | ||
self.assertEqual([b'--:\r\n'], list(obj._unread)) | ||
self.assertEqual(b'--:\r\n\r\nworld!\r\n--:--', stream.content.read()) | ||
|
||
def test_release_respects_content_length(self): | ||
obj = aiohttp.multipart.BodyPartReader( | ||
|
@@ -491,8 +491,7 @@ def test_release_release(self): | |
self.boundary, {}, stream) | ||
yield from obj.release() | ||
yield from obj.release() | ||
self.assertEqual(b'\r\nworld!\r\n--:--', stream.content.read()) | ||
self.assertEqual([b'--:\r\n'], list(obj._unread)) | ||
self.assertEqual(b'--:\r\n\r\nworld!\r\n--:--', stream.content.read()) | ||
|
||
def test_filename(self): | ||
part = aiohttp.multipart.BodyPartReader( | ||
|
@@ -501,6 +500,16 @@ def test_filename(self): | |
None) | ||
self.assertEqual('foo.html', part.filename) | ||
|
||
def test_reading_long_part(self): | ||
size = 2 * stream_reader_default_limit | ||
stream = StreamReader() | ||
stream.feed_data(b'0' * size + b'\r\n--:--') | ||
stream.feed_eof() | ||
obj = aiohttp.multipart.BodyPartReader( | ||
self.boundary, {}, stream) | ||
data = yield from obj.read() | ||
self.assertEqual(len(data), size) | ||
|
||
|
||
class MultipartReaderTestCase(TestCase): | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice!