The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Catalyst::Plugin::XSendFile - Catalyst plugin for lighttpd's X-Sendfile.

SYNOPSIS

    use Catalyst qw/XSendFile/;
    
    # manual send file
    sub show : Path('/files') {
        my ( $self, $c, $filename ) = @_;
    
        # unless login, it shows 403 forbidden screen
        $c->res->status(403);
        $c->stash->{template} = 'error-403.tt';
    
        # serving a static file only when user logged in.
        if ($c->user) {
            $c->res->sendfile( "/path/to/$filename" );
        }
    }
    
    
    # auto using x-send-tempfile on large content serving
    MyApp->config->{sendfile}{tempdir} = '/dev/shm';

NOTICE

This developer version of module requires lighttpd 1.5.0 (r1477) or above.

DESCRIPTION

lighty's X-Sendfile feature is great.

If you use lighttpd + fastcgi, you can show files only set X-Sendfile header like below:

    $c->res->header( 'X-LIGHTTPD-send-file' => $filename );

This feature is especially great for serving static file on authentication area.

And with this plugin, you can use:

    $c->res->sendfile( $filename );

instead of above.

But off-course you know, this feature doesn't work on Catalyst Test Server (myapp_server.pl). So this module also provide its emulation when your app on test server.

SERVE LARGE CONTENT BY X-LIGHTTPD-send-tempfile

Latest version of lighttpd (1.5.0) also support X-LIGHTTPD-send-tempfile, that is almost same to X-LIGHTTPD-send-file except deleting sending file when server sent file.

This module automatically use this feature when content length is above 16kbytes.

And for more performance, you need to set tempdir ($c->config->{sendfile}{tempdir}) on tmpfs (/dev/shm).

See below urls for detail.

SEE ALSO

lighty's life - X-Sendfile http://blog.lighttpd.net/articles/2006/07/02/x-sendfile

Faster - FastCGI http://blog.lighttpd.net/articles/2006/11/29/faster-fastcgi

NOTICE

To use it you have to set "allow-x-sendfile" option enabled in your fastcgi configuration.

    "allow-x-send-file" => "enable",

or on 1.5.0:

    proxy-core.allow-x-sendfile = "enable"

EXTENDED_METHODS

setup

Setup tempdir for x-send-tempfile

finalize_headers

Serving large (16kbytes) content via X-LIGHTTPD-send-tempfile.

EXTENDED_RESPONSE_METHODS

sendfile

Set X-LIGHTTPD-send-file header easily.

AUTHOR

Daisuke Murase <typester@cpan.org>

COPYRIGHT

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

The full text of the license can be found in the LICENSE file included with this module.