[Catalyst] Re: Serving a custom 404 page with Catalyst::Plugin::Static::Simple

Ash Berlin ash_cpan at firemirror.com
Thu Oct 11 09:02:12 GMT 2007


Will Hawes wrote:
> On 10/10/2007, *Will Hawes* <wdhawes at gmail.com
> <mailto:wdhawes at gmail.com>> wrote:
> 
>     With Catalyst::Plugin::Static::Simple loaded, when I request a path
>     like '/static/non-existent-file', the plugin does stuff like
>     $c->res->status(404) for me by default. However, as I already have
>     the following in MyApp::Controller::Root:
> 
>     sub default : Private {
>       my( $self, $c ) = @_;
>       $c->res->status( 404 );
>       $c->res->body( ...  );
>     }
> 
>     I'd like to use my existing default action to display something a
>     bit more user friendly when the requested static file is missing. In
>     this case I'm using the test server so bypassing
>     Catalyst::Plugin::Static::Simple completely is not an option.
> 
>     What's the correct way to implement the above?
> 
> 
> It seems as though the answer is to comment out the following in
> Catalyst::Plugin::Static::Simple (version 0.20):
> 
> $c->_debug_msg( "404: file not found: $path" )
>   if $config->{debug};
> $c->res->status( 404 );
> $c->res->content_type( 'text/html' );
> 
> Setting a HTTP status code other than 200 causes
> Catalyst::Plugin::Static::Simple::dispatch to bail out immediately, so
> Catalyst::Dispatcher::dispatch never gets called for a missing static
> file. Any default action in the app's root controller is ignored as a
> result.
> 
> Would a patch to remove the above lines (or at least make the behaviour
> configurable) be welcome?
> 

Sure. Please include tests.

Oh, and insert usual caveat that static::simple isn't really designed
for production use, but I realise it has its place.

-ash



More information about the Catalyst mailing list