9 use HTTP::Request::AsCGI;
12 $SIG{'PIPE'} = 'IGNORE';
14 my $server = HTTP::Daemon->new( LocalPort => 3000, ReuseAddr => 1 ) || die;
16 print "Please contact me at: <URL:", $server->url, ">\n";
18 while ( my $client = $server->accept ) {
21 REMOTE_ADDR => $client->peerhost,
22 REMOTE_HOST => $client->peerhost,
23 REMOTE_PORT => $client->peerport
26 while ( my $request = $client->get_request ) {
28 my $c = HTTP::Request::AsCGI->new( $request, %e )->setup;
32 $q->start_html('Hello World'),
33 $q->h1('Hello World'),
38 my $message = "HTTP/1.1 200\x0d\x0a";
40 while ( my $line = $c->stdout->getline ) {
42 last if $line =~ /^\x0d?\x0a$/;
45 my $response = HTTP::Response->parse($message);
47 if ( my $code = $response->header('Status') ) {
48 $response->code($code);
51 $response->header( Connection => 'close' );
52 $response->protocol( $request->protocol );
53 $response->content( sub {
54 if ( $c->stdout->read( my $buffer, 4096 ) ) {
60 $client->send_response($response);