I am using Python Flask + nginx with FCGI.
For some queries, I have to print large answers. Typically, these responses are retrieved from the socket. I am currently doing this answer:
response = [] while True: recv = s.recv(1024) if not recv: break response.append(recv) s.close() response = ''.join(response) return flask.make_response(response, 200, { 'Content-type': 'binary/octet-stream', 'Content-length': len(response), 'Content-transfer-encoding': 'binary', })
The problem is that I really don't need data. I also have a way to determine the exact length of the response received from the socket. Therefore, I need a good way to send HTTP headers, and then start outputting directly from the socket, and not collect it in memory, and then deliver it to nginx (possibly by some thread).
I could not find a solution to this seemingly common problem. How will this be achieved?
Thanks!
source share