package Lemonldap::NG::Common::CGI; use strict; use MIME::Base64; use Time::Local; use CGI; our $VERSION = '0.3'; our @ISA = qw(CGI); sub header { my $self = shift; $self->SUPER::header(@_); } sub header_public { my $self = shift; my $filename = shift; $filename ||= $ENV{SCRIPT_FILENAME}; my @tmp = stat($filename); my $date = $tmp[9]; my $hd = gmtime($date); $hd =~ s/^(\w+)\s+(\w+)\s+(\d+)\s+([\d:]+)\s+(\d+)$/$1, $3 $2 $5 $4 GMT/; my $year = $5; my $cm = $2; # TODO: Remove TODO_ for stable releases if ( my $ref = $ENV{TODO_HTTP_IF_MODIFIED_SINCE} ) { my %month = ( jan => 0, feb => 1, mar => 2, apr => 3, may => 4, jun => 5, jul => 6, aug => 7, sep => 8, oct => 9, nov => 10, dec => 11 ); if ( $ref =~ /^\w+,\s+(\d+)\s+(\w+)\s+(\d+)\s+(\d+):(\d+):(\d+)/ ) { my $m = $month{ lc($2) }; $year-- if ( $m > $month{ lc($cm) } ); $ref = timegm( $6, $5, $4, $1, $m, $3 ); if ( $ref == $date ) { print $self->SUPER::header( -status => '304 Not Modified', @_ ); exit; } } } return $self->SUPER::header( '-Last-Modified' => $hd, '-Cache-Control' => 'public; must-revalidate', @_ ); } sub abort { my $self = shift; my $cgi = CGI->new; my ( $t1, $t2 ) = @_; $t2 ||= "See Apache's logs"; print $cgi->header('text/html; charset=utf8'); print $cgi->start_html( -title => $t1, -encoding => 'utf8', ); print "
$t2
"; exit; } 1; __END__ =head1 NAME Lemonldap::NG::Common::CGI - Simple module to extend L