Apache2::FixupLastModified - Fixup handler for Last-Modified header


Apache2-FixupLastModified documentation Contained in the Apache2-FixupLastModified distribution.

Index


Code Index:

NAME

Top

Apache2::FixupLastModified - Fixup handler for Last-Modified header

VERSION

Top

Version 0.01

SYNOPSIS

Top

    # httpd.conf

    # preload for debug configuration directives
    PerlLoadModule   Apache2::FixupLastModified

    # assign to fixup handler
    PerlFixupHandler Apache2::FixupLastModified

DESCRIPTION

Top

Invoked as a Fixup handler, this module will adjust the Last-Modified header of a subrequested resource, should it be newer than the main request. Apache2::FixupLastModified is for use with resources that may arbitrarily include other resources (i.e. XSLT, server side includes, etc.) by way of subrequests.

DEBUGGING

Top

Debug levels start at 5 and end at 6. Below are the relevant debugging categories.

subreq

Enable for notification of the module's activation.

invoc

Enable for notification when the module does or doesn't do its job.

SEE ALSO

Top

Apache2::DebugLog

AUTHOR

Top

dorian taylor, <dorian@cpan.org>

BUGS

Top

Please report any bugs or feature requests to bug-apache2-fixuplastmodified@rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Apache2-FixupLastModified. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.

COPYRIGHT & LICENSE

Top


Apache2-FixupLastModified documentation Contained in the Apache2-FixupLastModified distribution.
package Apache2::FixupLastModified;

use warnings FATAL => 'all';
use strict;

use Apache2::RequestRec ();
use Apache2::Util       ();
use Apache2::DebugLog   ();

use Apache2::Const  -compile => qw(OK DECLINED);

use APR::Finfo          ();
use APR::Table          ();

use HTTP::Date          ();

our $VERSION = '0.01';

sub handler {
    my $r = shift;
    # we only operate on subrequests
    if (my $mr = $r->main and my $finfo = $r->finfo) {
        $r->log_debug('subreq', 5, 'Invoking handler on subrequest ' . $r->uri);
        my $hdr     = $mr->headers_out->get('Last-Modified');
        my $otime   = 0;
        if ($hdr) {
            $r->log_debug
                ('invoc', 6, 'Acquiring mtime from Last-Modified header');
            $otime = HTTP::Date::str2time($hdr);
        }
        elsif (my $mrf = $mr->finfo) {
            $r->log_debug
                ('invoc', 6, 'Acquiring mtime from main request\'s finfo');
            $otime = $mrf->mtime;
        }
        else {
            $r->log_debug('invoc', 5, 
                'No finfo or Last-Modified header in main request');
        }
        if ($otime < $finfo->mtime) {
            my $new = Apache2::Util::ht_time($r->pool, $finfo->mtime);
            $r->log_debugf('invoc', 5, 
                'Overwriting Last-Modified header "%s" with "%s"', 
                    $hdr || '', $new);
            $mr->headers_out->set('Last-Modified', $new);
            return Apache2::Const::OK;
        }
    }
    else {
        $r->log_debug('subreq', 6, 'Skipping main request' . $r->uri);
    }
    Apache2::Const::DECLINED;
}

1; # End of Apache2::FixupLastModified