12 our @ISA=qw(HTTP::Daemon);
14 my $CRLF = "\015\012"; # "\r\n" is not portable
17 my ($self, $urls) = @_;
19 while (my $con = $self->accept) {
20 while (my $req = $con->get_request) {
21 # print STDERR "method: ", $req->method, "\n";
22 if (exists($urls->{$req->url->path})) {
23 next unless ($req->method eq "HEAD" || $req->method eq "GET");
24 # print STDERR "requested URL: ", $req->url->path, "\n";
27 my $tmp = $urls->{$req->url->path};
28 my $resp = HTTP::Response->new ($tmp->{code},
30 # print STDERR "HTTP::Response: \n", $resp->as_string;
33 while (my ($name, $value) = each %{$tmp->{headers}}) {
34 # print STDERR "setting header: $name = $value\n";
35 $resp->header($name => $value);
37 # print STDERR "HTTP::Response with headers: \n", $resp->as_string;
39 if ($req->method eq "GET") {
40 if (exists($tmp->{headers}{"Content-Length"})) {
41 # Content-Length and length($tmp->{content}) don't match
42 # manually prepare the HTTP response
43 $con->send_basic_header($tmp->{code}, $resp->message, $resp->protocol);
44 print $con $resp->headers_as_string($CRLF);
46 print $con $tmp->{content};
50 $resp->content($tmp->{content});
51 # print STDERR "HTTP::Response with content: \n", $resp->as_string;
54 $con->send_response($resp);
55 # print STDERR "HTTP::Response sent: \n", $resp->as_string;
57 # print STDERR "requested wrong URL: ", $req->url->path, "\n";
58 $con->send_error($HTTP::Status::RC_FORBIDDEN);