From 235a6e43bcbe7587816809e75b963d5c4b025f99 Mon Sep 17 00:00:00 2001 From: Sergey Tikhonov Date: Mon, 24 Feb 2014 18:54:49 +0400 Subject: [PATCH 1/7] fix #14 without tests --- aiohttp/protocol.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/aiohttp/protocol.py b/aiohttp/protocol.py index ebf9b0479ba..dfd76607448 100644 --- a/aiohttp/protocol.py +++ b/aiohttp/protocol.py @@ -253,7 +253,7 @@ def __call__(self, out, buf): class HttpPayloadParser: - def __init__(self, message, length=None, compression=True, readall=False): + def __init__(self, message, length=None, compression=True, readall=True): self.message = message self.length = length self.compression = compression From 290b9c07df840529fd6a4fc30706444c856d42e5 Mon Sep 17 00:00:00 2001 From: Sergey Tikhonov Date: Mon, 2 Feb 2015 21:13:26 +0300 Subject: [PATCH 2/7] #263 functional and unit test for 100-continue --- tests/test_web_functional.py | 28 +++++++++++++++++++++++++++- tests/test_web_request.py | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 59 insertions(+), 1 deletion(-) diff --git a/tests/test_web_functional.py b/tests/test_web_functional.py index 2efd291e56e..ed79c41b8eb 100644 --- a/tests/test_web_functional.py +++ b/tests/test_web_functional.py @@ -4,7 +4,7 @@ import socket import unittest import tempfile -from aiohttp import web, request, FormData +from aiohttp import web, request, FormData, CIMultiDict from aiohttp.multidict import MultiDict @@ -95,6 +95,32 @@ def go(): self.loop.run_until_complete(go()) + def test_post_100_continue(self): + @asyncio.coroutine + def handler(request): + data = yield from request.post() + self.assertEqual(b'123', data['name']) + return web.Response() + + @asyncio.coroutine + def go(): + _, _, url = yield from self.create_server('POST', '/', handler) + + form = FormData() + form.add_field('name', b'123', + content_transfer_encoding='base64') + + resp = yield from request( + 'post', url, data=form, + expect100=True, # wait until server returns 100 continue + loop=self.loop) + + self.assertEqual(200, resp.status) + + self.loop.run_until_complete( + asyncio.wait_for(go(), timeout=0.1, loop=self.loop)) + + def test_post_json(self): dct = {'key': 'текст'} diff --git a/tests/test_web_request.py b/tests/test_web_request.py index eddcb3eb78f..c9436890edc 100644 --- a/tests/test_web_request.py +++ b/tests/test_web_request.py @@ -116,6 +116,38 @@ def test_call_POST_on_GET_request(self): ret = self.loop.run_until_complete(req.post()) self.assertEqual(CIMultiDict(), ret) + def test_call_POST_for_100_continue(self): + body = b"123" + req = self.make_request( + 'POST', '/', + headers=CIMultiDict({"EXPECT": "100-Continue", 'CONTENT-TYPE': ''})) + with mock.patch.object(req, "read", side_effect=StopIteration(body)): + ret = self.loop.run_until_complete(req.post()) + self.assertEqual(ret, body) + req.transport.write.assert_called_with(b'HTTP/1.1 100 Continue\r\n\r\n') + + def test_call_POST_for_100_continue_HTTP10(self): + body = b"123" + req = self.make_request( + 'POST', '/', + headers=CIMultiDict({"EXPECT": "100-Continue", 'CONTENT-TYPE': ''}), + version=HttpVersion(1, 0)) + + with mock.patch.object(req, "read", side_effect=StopIteration(body)): + ret = self.loop.run_until_complete(req.post()) + self.assertEqual(ret, body) + self.assertFalse(req.transport.write.call_args_list) + + def test_call_POST_for_other_expect(self): + body = b"123" + req = self.make_request( + 'POST', '/', + headers=CIMultiDict({"EXPECT": "Other-thing", 'CONTENT-TYPE': ''})) + with mock.patch.object(req, "read", side_effect=StopIteration(body)): + ret = self.loop.run_until_complete(req.post()) + self.assertEqual(ret, body) + self.assertFalse(req.transport.write.call_args_list) + def test_call_POST_on_weird_content_type(self): req = self.make_request( 'POST', '/', From 8cb2c182af5a9be835cc72b084fac5b63b9f33d1 Mon Sep 17 00:00:00 2001 From: Sergey Tikhonov Date: Mon, 2 Feb 2015 21:13:53 +0300 Subject: [PATCH 3/7] #263 fix Request.post for 100-continue --- aiohttp/web.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/aiohttp/web.py b/aiohttp/web.py index 366d44cba7e..3008be6e6b7 100644 --- a/aiohttp/web.py +++ b/aiohttp/web.py @@ -348,6 +348,10 @@ def post(self): self._post = MultiDictProxy(MultiDict()) return self._post + if self.headers.get('expect', '').lower() == "100-continue": + if self.version == HttpVersion11: + self.transport.write(b"HTTP/1.1 100 Continue\r\n\r\n") + body = yield from self.read() content_charset = self.charset or 'utf-8' From eaf724c88d9d96ba728eb5cfaa2bdcd6899e03dc Mon Sep 17 00:00:00 2001 From: Sergey Tikhonov Date: Mon, 2 Feb 2015 21:20:19 +0300 Subject: [PATCH 4/7] #263 remove unused import --- tests/test_web_functional.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_web_functional.py b/tests/test_web_functional.py index ed79c41b8eb..472262bc1d9 100644 --- a/tests/test_web_functional.py +++ b/tests/test_web_functional.py @@ -4,7 +4,7 @@ import socket import unittest import tempfile -from aiohttp import web, request, FormData, CIMultiDict +from aiohttp import web, request, FormData from aiohttp.multidict import MultiDict From 9e17320ee8baa685c1c850686a5ceef1be42c1c0 Mon Sep 17 00:00:00 2001 From: Sergey Tikhonov Date: Mon, 2 Feb 2015 21:24:06 +0300 Subject: [PATCH 5/7] #263 pyflakes --- tests/test_web_functional.py | 1 - tests/test_web_request.py | 12 ++++++++---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/tests/test_web_functional.py b/tests/test_web_functional.py index 472262bc1d9..591d01270d0 100644 --- a/tests/test_web_functional.py +++ b/tests/test_web_functional.py @@ -120,7 +120,6 @@ def go(): self.loop.run_until_complete( asyncio.wait_for(go(), timeout=0.1, loop=self.loop)) - def test_post_json(self): dct = {'key': 'текст'} diff --git a/tests/test_web_request.py b/tests/test_web_request.py index c9436890edc..f0ec725973b 100644 --- a/tests/test_web_request.py +++ b/tests/test_web_request.py @@ -120,17 +120,20 @@ def test_call_POST_for_100_continue(self): body = b"123" req = self.make_request( 'POST', '/', - headers=CIMultiDict({"EXPECT": "100-Continue", 'CONTENT-TYPE': ''})) + headers=CIMultiDict({"EXPECT": "100-Continue", + 'CONTENT-TYPE': ''})) with mock.patch.object(req, "read", side_effect=StopIteration(body)): ret = self.loop.run_until_complete(req.post()) self.assertEqual(ret, body) - req.transport.write.assert_called_with(b'HTTP/1.1 100 Continue\r\n\r\n') + req.transport.write.assert_called_with( + b'HTTP/1.1 100 Continue\r\n\r\n') def test_call_POST_for_100_continue_HTTP10(self): body = b"123" req = self.make_request( 'POST', '/', - headers=CIMultiDict({"EXPECT": "100-Continue", 'CONTENT-TYPE': ''}), + headers=CIMultiDict({"EXPECT": "100-Continue", + 'CONTENT-TYPE': ''}), version=HttpVersion(1, 0)) with mock.patch.object(req, "read", side_effect=StopIteration(body)): @@ -142,7 +145,8 @@ def test_call_POST_for_other_expect(self): body = b"123" req = self.make_request( 'POST', '/', - headers=CIMultiDict({"EXPECT": "Other-thing", 'CONTENT-TYPE': ''})) + headers=CIMultiDict({"EXPECT": "Other-thing", + 'CONTENT-TYPE': ''})) with mock.patch.object(req, "read", side_effect=StopIteration(body)): ret = self.loop.run_until_complete(req.post()) self.assertEqual(ret, body) From 1cc0288e2cbe03808f38af6a72c5c1770e4672f3 Mon Sep 17 00:00:00 2001 From: Sergey Tikhonov Date: Mon, 2 Feb 2015 21:25:38 +0300 Subject: [PATCH 6/7] #263 fix failed test_xor --- tests/test_multidict.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_multidict.py b/tests/test_multidict.py index 5c5220a33c4..cc8964d84d3 100644 --- a/tests/test_multidict.py +++ b/tests/test_multidict.py @@ -201,7 +201,7 @@ def test_sub(self): "Set operations on views not supported") def test_xor(self): d = self.make_dict([('key', 'value1'), ('key2', 'value2')]) - self.assertEqual({'key', 'key3'}, d.keys() ^ {'key2', 'key3'}) + self.assertEqual({'key', 'key3'}, set(d.keys()) ^ {'key2', 'key3'}) @unittest.skipIf(HAS_NO_SET_OPS_FOR_VIEW, "Set operations on views not supported") From 3bea11111dc0119f3d8f19a77735993f791dbfa0 Mon Sep 17 00:00:00 2001 From: Sergey Tikhonov Date: Mon, 2 Feb 2015 21:31:34 +0300 Subject: [PATCH 7/7] #263 actually test_xor was not fixed --- tests/test_multidict.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_multidict.py b/tests/test_multidict.py index cc8964d84d3..5c5220a33c4 100644 --- a/tests/test_multidict.py +++ b/tests/test_multidict.py @@ -201,7 +201,7 @@ def test_sub(self): "Set operations on views not supported") def test_xor(self): d = self.make_dict([('key', 'value1'), ('key2', 'value2')]) - self.assertEqual({'key', 'key3'}, set(d.keys()) ^ {'key2', 'key3'}) + self.assertEqual({'key', 'key3'}, d.keys() ^ {'key2', 'key3'}) @unittest.skipIf(HAS_NO_SET_OPS_FOR_VIEW, "Set operations on views not supported")