I have the following Werkzeug application to return a file to a client:
from werkzeug.wrappers import Request, Response @Request.application def application(request): fileObj = file(r'C:\test.pdf','rb') response = Response( response=fileObj.read() ) response.headers['content-type'] = 'application/pdf' return response
I want to focus on this part:
response = Response( response=fileObj.read() )
In this case, the response takes about 500 ms ( C:\test.pdf is a 4 MB file. The web server is on my local machine).
But if I rewrote this line:
response = Response() response.response = fileObj
Now the answer takes about 1500 ms. (3 times slower)
And if you write it like this:
response = Response() response.response = fileObj.read()
Now the answer takes about 80 seconds (right, 80 SECONDS).
Why is there such a big difference between the three methods?
And why is the third sooooo method slow?
source share