package TestHTML; use Module::Util qw(find_installed); use HTTP::Daemon::Threaded::Content; use HTTP::Date qw(time2str); use HTTP::Status; use HTTP::Response; use base ('HTTP::Daemon::Threaded::Content'); use strict; use warnings; our %pages = ( 'index' => \&mainPage, 'frames' => \&framePage, 'stackpage' => \&stackPage, 'stackpane' => \&stackPane, 'sourcepane' => \&sourcePane, 'sourcetree' => \&sourceTree, ); our $mtime = time2str((stat(find_installed(__PACKAGE__)))[9]); sub new { my $class = shift; return $class->SUPER::new(@_); } sub getContent { my ($self, $fd, $req, $uri, $params, $session) = @_; # print STDERR "Session ", (defined($session) ? 'exists' : 'undef'), "\n"; unless (($uri=~/\/(\w+)\.html$/i) && (exists $pages{$1})) { $self->logInfo("Can't find $1\n"); return $fd->send_error(RC_NOT_FOUND); } $session = $self->{SessionCache}->createSession() unless $session; my $html = $pages{$1}->(); my $res = HTTP::Response->new(RC_OK); $res->header('Content-Type' => 'text/html'); $res->header('Last-Modified' => $mtime); $res->header('Set-Cookie' => $session->getCookie()), $session->cookieSent() if $session->isNew(); $res->content($html); $self->logInfo("sending response\n"); return $fd->send_response($res); } sub getHeader { my ($self, $fd, $req, $uri, $params, $session) = @_; # print STDERR "Session ", (defined($session) ? 'exists' : 'undef'), "\n"; unless (($uri=~/\/(\w+)\.html$/i) && (exists $pages{$1})) { $self->logInfo("Can't HEAD $1\n"); return $fd->send_error(RC_NOT_FOUND); } $session = $self->{SessionCache}->createSession() unless $session; my $html = $pages{$1}->(); my $res = HTTP::Response->new(RC_OK, 'OK', [ 'Content-Type' => 'text/html', 'Content-Length' => length($html), 'Last-Modified' => $mtime, ]); $res->header('Set-Cookie' => $session->getCookie()), $session->cookieSent() if $session->isNew(); $res->request($req); return $fd->send_response($res); } # # the main frameset page # the title is set from the input app name # sub mainPage { return '
Some really simple HTML.'; } sub framePage { return "| Frame | Package::method() | Line |
|---|