12 our @ISA=qw(HTTP::Daemon);
15 my $CRLF = "\015\012"; # "\r\n" is not portable
19 my ($self, $urls) = @_;
21 while (my $con = $self->accept) {
22 while (my $req = $con->get_request) {
23 print STDERR "Method: ", $req->method, "\n" if $log;
24 print STDERR "Path: ", $req->url->path, "\n" if $log;
25 foreach my $key (keys %{HTTPServer::urls}) {
26 print STDERR $key, '\n';
28 if (exists($urls->{$req->url->path})) {
29 print STDERR "Serving requested URL: ", $req->url->path, "\n" if $log;
30 next unless ($req->method eq "HEAD" || $req->method eq "GET");
33 my $tmp = $urls->{$req->url->path};
34 my $resp = HTTP::Response->new ($tmp->{code},
36 print STDERR "HTTP::Response: \n", $resp->as_string if $log;
38 #if (is_dynamic_url) { # dynamic resource
39 #} else { # static resource
41 while (my ($name, $value) = each %{$tmp->{headers}}) {
42 # print STDERR "setting header: $name = $value\n";
43 $resp->header($name => $value);
45 print STDERR "HTTP::Response with headers: \n", $resp->as_string if $log;
47 if ($req->method eq "GET") {
48 if (exists($tmp->{headers}{"Content-Length"})) {
49 # Content-Length and length($tmp->{content}) don't match
50 # manually prepare the HTTP response
51 $con->send_basic_header($tmp->{code}, $resp->message, $resp->protocol);
52 print $con $resp->headers_as_string($CRLF);
54 print $con $tmp->{content};
58 $resp->content($tmp->{content});
59 print STDERR "HTTP::Response with content: \n", $resp->as_string if $log;
63 $con->send_response($resp);
64 print STDERR "HTTP::Response sent: \n", $resp->as_string if $log;
66 print STDERR "Requested wrong URL: ", $req->url->path, "\n" if $log;
67 $con->send_error($HTTP::Status::RC_FORBIDDEN);