| 1042 | web.StaticRoute(None, "/", nodirectory) |
| 1043 | |
| 1044 | def test_static_file_huge(self): |
| 1045 | |
| 1046 | @asyncio.coroutine |
| 1047 | def go(dirname, filename): |
| 1048 | app, _, url = yield from self.create_server( |
| 1049 | 'GET', '/static/' + filename |
| 1050 | ) |
| 1051 | app.router.add_static('/static', dirname) |
| 1052 | |
| 1053 | resp = yield from request('GET', url, loop=self.loop) |
| 1054 | self.assertEqual(200, resp.status) |
| 1055 | ct = resp.headers['CONTENT-TYPE'] |
| 1056 | self.assertEqual('application/octet-stream', ct) |
| 1057 | self.assertIsNone(resp.headers.get('CONTENT-ENCODING')) |
| 1058 | self.assertEqual(int(resp.headers.get('CONTENT-LENGTH')), |
| 1059 | file_st.st_size) |
| 1060 | |
| 1061 | f = open(fname, 'rb') |
| 1062 | off = 0 |
| 1063 | cnt = 0 |
| 1064 | while off < file_st.st_size: |
| 1065 | chunk = yield from resp.content.readany() |
| 1066 | expected = f.read(len(chunk)) |
| 1067 | self.assertEqual(chunk, expected) |
| 1068 | off += len(chunk) |
| 1069 | cnt += 1 |
| 1070 | f.close() |
| 1071 | resp.close() |
| 1072 | |
| 1073 | here = os.path.dirname(__file__) |
| 1074 | filename = 'huge_data.unknown_mime_type' |
| 1075 | |
| 1076 | # fill 100MB file |
| 1077 | fname = os.path.join(here, filename) |
| 1078 | with open(fname, 'w') as f: |
| 1079 | for i in range(1024*20): |
| 1080 | f.write(chr(i % 64 + 0x20) * 1024) |
| 1081 | self.addCleanup(os.unlink, fname) |
| 1082 | file_st = os.stat(fname) |
| 1083 | |
| 1084 | self.loop.run_until_complete(go(here, filename)) |
| 1085 | |
| 1086 | def test_env_nosendfile(self): |
| 1087 | directory = os.path.dirname(__file__) |