Scags9876 has asked for the wisdom of the Perl Monks concerning the following question:

I have a problem where a client can send an https request that will build a zip file and send it to the user. Sometimes these zip files are very very large. It can take upwards of 10 minutes to build it. In the meantime, the connection is severed by the client's firewall (or some such mechanism).

In the past, I have solved this problem by sending a keepalive to the client in the form of:

$r->print(" "); $r->rflush();

This works well when the headers are already sent and the content type is text/html or text/plain (while processing an upload for example, prior to showing any results of processing). However, this does not work when the content type is 'application/zip'.

How do I send some keep alive information to the client while the file is building when the eventual content type of the response is 'application/zip'?

Here's what I'm doing, in a nutshell, which is not working:

my $r = Apache2::Request->new(); while($file_is_not_finished) { ... write a bunch of stuff to $file $r->print(" "); $r->rflush(); } $r->content_type('application/zip'); $r->headers_out->set( 'Content-disposition' => "attachment;filename=\"\"" ); my $fh; open($fh, $file) or die $!; $r->print(<$fh>);

Sorry if my pseudo code is not clear, let me know if further clarification would be helpful.

The observed behavior is that the client browser just ends the connection, with no message or indication of error.