[Catalyst] How to send raw HTTP response

Matt S Trout dbix-class at trout.me.uk
Sat Sep 27 19:48:01 BST 2008

On Thu, Sep 25, 2008 at 08:35:14PM +0200, Christian Lackas wrote:
> Hi Everybody,
> is it possible for a controller method to directly produce the raw HTTP response?
> My application generates a (potentially large)) ZIP file on the fly,
> which I don't want to store (on disk or in memory) but rather send it
> directly to the client while producing it.
> In a CGI script I use Archive::Zip such as
>     print CGI::header(...);
>     $ZIP->writeToFileHandle(*STDOUT);
>     for my $f (@files) {
>         $ZIP->addFile($f, basename($f));
>     }
> How can I achieve something similar under Catalyst?

Just call $c->write($chunk) with each chunk of data as you get it.

Catalyst will automatically send headers before the first chunk for you.

Do -not- rely on STDOUT being an appropriate filehandle to print to, that's
an accident of the engine design and could easily go away.

      Matt S Trout       Need help with your Catalyst or DBIx::Class project?
   Technical Director                    http://www.shadowcat.co.uk/catalyst/
 Shadowcat Systems Ltd.  Want a managed development or deployment platform?
http://chainsawblues.vox.com/            http://www.shadowcat.co.uk/servers/

More information about the Catalyst mailing list