Commit 34778ed818ed3fea1ebc4d8f80e82e19fd4beb74
1 parent
3586cfab
Exists in
master
and in
1 other branch
FileHandler now serves the complete file instead of chunks.
Showing
1 changed file
with
17 additions
and
12 deletions
Show diff stats
serve.py
... | ... | @@ -182,7 +182,9 @@ class TopicHandler(BaseHandler): |
182 | 182 | # Based on https://bhch.github.io/posts/2017/12/serving-large-files-with-tornado-safely-without-blocking/ |
183 | 183 | # ---------------------------------------------------------------------------- |
184 | 184 | class FileHandler(BaseHandler): |
185 | - chunk_size = 4 * 1024 * 1024 # serve up to 4 MiB multiple times | |
185 | + SUPPORTED_METHODS = ['GET'] | |
186 | + | |
187 | + # chunk_size = 4 * 1024 * 1024 # serve up to 4 MiB multiple times | |
186 | 188 | |
187 | 189 | @tornado.web.authenticated |
188 | 190 | async def get(self, filename): |
... | ... | @@ -203,17 +205,20 @@ class FileHandler(BaseHandler): |
203 | 205 | # divide the file into chunks and write one chunk at a time, so |
204 | 206 | # that the write does not block the ioloop for very long. |
205 | 207 | with f: |
206 | - chunk = f.read(self.chunk_size) | |
207 | - while chunk: | |
208 | - try: | |
209 | - self.write(chunk) # write the chunk to response | |
210 | - await self.flush() # flush the current chunk to socket | |
211 | - except iostream.StreamClosedError: | |
212 | - break # client closed the connection | |
213 | - finally: | |
214 | - del chunk | |
215 | - await asyncio.sleep(0) # 1 nanosecond (hack) | |
216 | - chunk = f.read(self.chunk_size) | |
208 | + self.write(f.read()) | |
209 | + await self.flush() | |
210 | + | |
211 | + # chunk = f.read(self.chunk_size) | |
212 | + # while chunk: | |
213 | + # try: | |
214 | + # self.write(chunk) # write the chunk to response | |
215 | + # await self.flush() # flush the current chunk to socket | |
216 | + # except iostream.StreamClosedError: | |
217 | + # break # client closed the connection | |
218 | + # finally: | |
219 | + # del chunk | |
220 | + # await asyncio.sleep(0) # 1 nanosecond (hack) | |
221 | + # chunk = f.read(self.chunk_size) | |
217 | 222 | |
218 | 223 | |
219 | 224 | # ---------------------------------------------------------------------------- | ... | ... |