Skip to content

Instantly share code, notes, and snippets.

@ranguard
Created March 15, 2012 10:55
Show Gist options
  • Select an option

  • Save ranguard/2043619 to your computer and use it in GitHub Desktop.

Select an option

Save ranguard/2043619 to your computer and use it in GitHub Desktop.
Insane writer?
#!/usr/bin/env perl
use strict;
use Plack::Builder;
use Plack::Middleware::ErrorDocument;
my $root = '/home/leo/git/fab/vhosts/ah/docs/www';
my $app = sub {
sub {
my $respond = shift;
my $writer = $respond->([404, ['Content-Type' => 'text/html', 'Content-Length' => 3]]);
if (!ref($writer) || !eval {$writer->can("write") and $writer->can("close")}) {
die("writer is insane!");
}
else {
$writer->write('foo');
$writer->close;
}
};
};
$app = Plack::Middleware::ErrorDocument->wrap( #
$app,
404 => "$root/page_not_found.html",
);
my $app = builder {
$app;
};
$app; # return
@ranguard
Copy link
Copy Markdown
Author

Plack: 0.9986
Moose: 2.0402 (all moose modules also updated)
Catalyst: 5.90011
Starman: 0.300

Discussing on #catalyst (which is where the $app sub came from)

11:16 @t0m Ranguard: yes, and it's something to do with the subrequest, I think
11:19 @t0m Ranguard: ah, ok, I think I just understood..
11:19 @t0m Sooo, what happens is..
11:19 @t0m Catalyst app gets called, returns 404
11:20 @t0m ErrorDocument gets called, substitutes the response with the opened FH for the error file to serve...
11:20 @t0m Catalyst then gets passed back it's body writer
11:20 @t0m which errordocument has just scribbled on
11:20 @t0m Catalyst throws a fit..
11:21 @t0m I think this is a bug in Plack::Util::response_cb

@miyagawa
Copy link
Copy Markdown

ErrorDocument's subrequest was a bad idea and doesn't support streaming.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment