Apache-WinBitHack
view release on metacpan or search on metacpan
WinBitHack.pm view on Meta::CPAN
sub handler {
# Implement XBitHack on Win32.
# Usage: PerlModule Apache::WinBitHack
# PerlFixupHandler Apache::WinBitHack
# XBitHack On|Off|Full
my $r = shift;
my $cfg = Apache::ModuleConfig->get($r, __PACKAGE__);
return DECLINED unless (
$^O =~ m/Win32/ && # we're on Win32
-f $r->finfo && # the file exists
$r->content_type eq 'text/html' && # and is HTML
$r->allow_options & OPT_INCLUDES && # and we have Options +Includes
$cfg->{_state} ne 'OFF'); # and XBitHack On or Full
# Gather the file attributes.
my $attr;
Win32::File::GetAttributes($r->filename, $attr);
# Return DECLINED if the file has the ARCHIVE attribute set,
# which is the usual case.
return DECLINED if $attr & ARCHIVE();
# Set the Last-Modified header unless the READONLY attribute is set.
if ($cfg->{_state} eq 'FULL') {
$r->set_last_modified((stat _)[9]) unless $attr & READONLY();
}
# Make sure mod_include picks it up.
$r->handler('server-parsed');
return OK;
}
sub DIR_CREATE {
my $class = shift;
my %self = ();
# XBitHack is disabled by default.
$self{_state} = "OFF";
return bless \%self, $class;
}
sub DIR_MERGE {
my ($parent, $current) = @_;
my %new = (%$parent, %$current);
return bless \%new, ref($parent);
}
sub XBitHack ($$$) {
my ($cfg, $parms, $arg) = @_;
# Let mod_include do the Unix stuff - we only do Win32.
return DECLINE_CMD unless $^O =~ m/Win32/;
if ($arg =~ m/^(On|Off|Full)$/i) {
$cfg->{_state} = uc($arg);
}
else {
die "Invalid XBitHack $arg!";
}
}
1;
__END__
=head1 NAME
Apache::WinBitHack - An Apache module to emulate XBitHack on Win32
=head1 SYNOPSIS
In Apache's F<httpd.conf>:
PerlModule Apache::WinBitHack
<Directory "/Apache/htdocs/some_dir">
SetHandler perl-script
PerlFixupHandler Apache::WinBitHack
XBitHack Full
Options MultiViews Indexes Includes
</Directory>
=head1 DESCRIPTION
Apache contains a very useful directive C<XBitHack>, whereby a file
that has the user-execute bit set will be treated as a server-parsed
html document. As well, the group-execute bit can be used to set
the Last-modified time of the returned file to be the last modified
time of the file, which is useful in determining if a document is
to be cached or not. On Win32 the directive works in principle, but
in an inconvenient fashion - the execute bit is set on Win32 by the
file extension, which means that documents that are to take advantage
of C<XBitHack> must have an extension like C<exe> or C<bat>.
This module emulates C<XBitHack> on Win32 by, rather than using the
user and group execute bits, using instead the attributes
of the file to determine if the file is to be server-parsed by mod_include.
Attributes of a file on Win32, which you can see by running
C:\> attrib file_name
include C<archive>, C<hidden>, C<read-only>, and C<system>. Normal
user files have just the C<archive> attribute set, which some back-up
programs use to determine if the file should be included in the next
incremental backup (most backup programs now instead use the
last-modified-time of the file for this purpose). By setting certain
attributes of the file and specifying directives as in the SYNOPSIS,
particularly the C<Includes> option,
C<XBitHack> can be emulated in the following ways.
=head2 XBitHack Off
( run in 1.036 second using v1.01-cache-2.11-cpan-39bf76dae61 )