14 my $server = HTTP::Daemon->new (LocalAddr => 'localhost',
16 ReuseAddr => 1) or die "Cannot create server!!!";
18 while (my $con = $server->accept) {
19 while (my $req = $con->get_request) {
20 # print STDERR "method: ", $req->method, "\n";
21 if ($req->method eq "GET" and $urls{$req->url->path}) {
22 # print STDERR "requested URL: ", $req->url->path, "\n";
25 my $tmp = $urls{$req->url->path};
26 my $resp = HTTP::Response->new ($tmp->{'code'},
28 # print STDERR "HTTP::Response: \n", $resp->as_string;
31 while (my ($name, $value) = each %{$tmp->{headers}}) {
32 # print STDERR "setting header: $name = $value\n";
33 $resp->header($name => $value);
35 # print STDERR "HTTP::Response with headers: \n", $resp->as_string;
38 $resp->content($tmp->{content});
39 # print STDERR "HTTP::Response with content: \n", $resp->as_string;
41 $con->send_response($resp);
42 # print STDERR "HTTP::Response sent: \n", $resp->as_string;
44 print STDERR "requested wrong URL: ", $req->url->path, "\n";
45 $con->send_error($HTTP::Status::RC_FORBIDDEN);