[Catalyst] How to send raw HTTP response
Christian Lackas
christian at lackas.net
Fri Sep 26 13:38:47 BST 2008
* Tomas Doran <bobtfish at bobtfish.net> [080925 23:06]:
Hi Tomas,
thanks for the prompt reply (also to all others).
> Looking at the source code for Catalyst::write, and
> Catalyst::Engine::write, you need to say $c->finalize_headers, after
> which just writing to STDOUT as above should do the right thing..
This is supposed to print out the HTTP header immediately, right?
I tried this here:
sub download : Local {
my ($self, $c) = @_;
my ($filename, @files) = getAllfiles();
$c->response->content_type('application/zip');
$c->response->header('Content-Disposition' => "attachment; filename=$filename.zip");
$c->finalize_headers();
$c->response->{body} = undef;
my $ZIP = Archive::Zip->new();
foreach my $file (@files) {
my ($basename) = $file =~ m{.*/(.*)};
$ZIP->addFile($file, $basename);
}
$ZIP->writeToFileHandle(*STDOUT);
}
However, with this code I don't get a HTTP header at all (when run under
Catalyst server) and additionally Catalyst appends an error message
after my ZIP file.
So my questions are:
How do I tell Catalyst:
- to either send no HTTP header at all, or to force it to print the
header at a time convenient for me (e.g. just before the ZIP)?
- that I handled everything in the controller and that it should just
stop with processing the request (so nothing is send afterwards).
> However, I'd have thought that clients on the other end would be
> somewhat unhappy with not getting a Content-Length header...
As pointed out in this thread already, this mainly means that a browser
is not able to show a proper progress bar. If the ZIP is downloaded
incompletely, even though the browser may not able to report that
correctly, the uncompressing will fail with a truncation warning.
Christian
More information about the Catalyst
mailing list