| 1 |
# Thanks to merlyn for nudging me and giving me this snippet! |
| 2 |
|
| 3 |
use HTTP::Daemon (); |
| 4 |
|
| 5 |
$|++; |
| 6 |
|
| 7 |
my $d = HTTP::Daemon->new or die; |
| 8 |
print $d->url, "\n"; |
| 9 |
|
| 10 |
$counter = 6; |
| 11 |
while ( $counter-- and my $c = $d->accept ) { |
| 12 |
while ( my $r = $c->get_request ) { |
| 13 |
my $location = ( $r->uri->path || "/" ); |
| 14 |
if ( $location eq '/quit_server' ) { |
| 15 |
$c->send_response( |
| 16 |
HTTP::Response->new( |
| 17 |
200, "OK", [ Connection => 'close' ], "quit" |
| 18 |
) |
| 19 |
); |
| 20 |
$counter = 0; |
| 21 |
last; |
| 22 |
} |
| 23 |
else { |
| 24 |
my $ref = $r->headers->referer || ""; |
| 25 |
$c->send_response( |
| 26 |
HTTP::Response->new( 200, "OK", undef, "Referer: '$ref'" ) ); |
| 27 |
} |
| 28 |
} |
| 29 |
$c->close; |
| 30 |
undef($c); |
| 31 |
} |