I am writing a cgi page in Python. Let\'s say a client sends request to my cgi page. My cgi page does the calculation and as soon as it has the first output, it sends back t
The trick in old-fashioned CGI
programs is using the Transfer-Encoding: chunked HTTP header:
3.6.1 Chunked Transfer Coding
The chunked encoding modifies the body of a message in order to transfer it as a series of chunks, each with its own size indicator, followed by an OPTIONAL trailer containing entity-header fields. This allows dynamically produced content to be transferred along with the information necessary for the recipient to verify that it has received the full message.
When a result is available, send it as a separate chunk - the browser will display this self-contained HTTP message. When another chunk arrives later, a NEW PAGE is displayed.
You'll have to produce the correct headers for each chunk inside the CGI
program. Also, remember to flush the CGI
output at the end of each chunk. In Python this is done with sys.stdout.flush()