|
1 | 1 | import asyncio
|
2 | 2 | import unittest
|
3 | 3 | from unittest import mock
|
| 4 | +from aiohttp import hdrs |
4 | 5 | from aiohttp.multidict import CIMultiDict
|
5 | 6 | from aiohttp.web import Request, StreamResponse, Response
|
6 | 7 | from aiohttp.protocol import RawRequestMessage, HttpVersion11
|
@@ -138,6 +139,50 @@ def test_chunk_size(self, ResponseImpl):
|
138 | 139 |
|
139 | 140 | msg = resp.start(req)
|
140 | 141 | self.assertTrue(msg.chunked)
|
| 142 | + msg.add_chunking_filter.assert_called_with(8192) |
| 143 | + self.assertIsNotNone(msg.filter) |
| 144 | + |
| 145 | + @mock.patch('aiohttp.web.ResponseImpl') |
| 146 | + def test_compression_no_accept(self, ResponseImpl): |
| 147 | + req = self.make_request('GET', '/') |
| 148 | + resp = StreamResponse() |
| 149 | + self.assertFalse(resp.chunked) |
| 150 | + |
| 151 | + self.assertFalse(resp.compression) |
| 152 | + resp.enable_compression() |
| 153 | + self.assertTrue(resp.compression) |
| 154 | + |
| 155 | + msg = resp.start(req) |
| 156 | + self.assertFalse(msg.add_compression_filter.called) |
| 157 | + |
| 158 | + @mock.patch('aiohttp.web.ResponseImpl') |
| 159 | + def test_force_compression_no_accept(self, ResponseImpl): |
| 160 | + req = self.make_request('GET', '/') |
| 161 | + resp = StreamResponse() |
| 162 | + self.assertFalse(resp.chunked) |
| 163 | + |
| 164 | + self.assertFalse(resp.compression) |
| 165 | + resp.enable_compression(force=True) |
| 166 | + self.assertTrue(resp.compression) |
| 167 | + |
| 168 | + msg = resp.start(req) |
| 169 | + self.assertTrue(msg.add_compression_filter.called) |
| 170 | + self.assertIsNotNone(msg.filter) |
| 171 | + |
| 172 | + @mock.patch('aiohttp.web.ResponseImpl') |
| 173 | + def test_compression(self, ResponseImpl): |
| 174 | + req = self.make_request( |
| 175 | + 'GET', '/', |
| 176 | + headers=CIMultiDict({str(hdrs.ACCEPT_ENCODING): 'gzip, deflate'})) |
| 177 | + resp = StreamResponse() |
| 178 | + self.assertFalse(resp.chunked) |
| 179 | + |
| 180 | + self.assertFalse(resp.compression) |
| 181 | + resp.enable_compression() |
| 182 | + self.assertTrue(resp.compression) |
| 183 | + |
| 184 | + msg = resp.start(req) |
| 185 | + self.assertTrue(msg.add_compression_filter.called) |
141 | 186 | self.assertIsNotNone(msg.filter)
|
142 | 187 |
|
143 | 188 | def test_write_non_byteish(self):
|
|
0 commit comments