| 1 |
#!perl -w |
| 2 |
# Thanks to merlyn for nudging me and giving me this snippet! |
| 3 |
use strict; |
| 4 |
|
| 5 |
require HTTP::Daemon; |
| 6 |
|
| 7 |
our $VERSION = '0.67'; |
| 8 |
|
| 9 |
$|++; |
| 10 |
|
| 11 |
my $d = HTTP::Daemon->new or die; |
| 12 |
print $d->url, "\n"; |
| 13 |
|
| 14 |
# How many requests do we expect? |
| 15 |
my ($ex_user,$ex_pass) = @ARGV; |
| 16 |
|
| 17 |
my $verbose = $ENV{TEST_HTTP_VERBOSE}; |
| 18 |
|
| 19 |
my $done = 0; |
| 20 |
while (! $done and my $c = $d->accept) { |
| 21 |
while (my $req = $c->get_request) { |
| 22 |
if ($verbose) { |
| 23 |
warn "# Request URI: " . $req->url->path; |
| 24 |
my @lines = split "\n",$req->as_string; |
| 25 |
warn "# $_\n" for @lines; |
| 26 |
}; |
| 27 |
|
| 28 |
my $res; |
| 29 |
my ($user,$pass); |
| 30 |
if ($req->url->path eq '/exit') { |
| 31 |
$done = 1; |
| 32 |
$res = HTTP::Response->new(200, "OK", undef, "done"); |
| 33 |
}; |
| 34 |
|
| 35 |
if ($verbose) { |
| 36 |
warn "---\n"; |
| 37 |
my @lines = split "\n",$res->as_string; |
| 38 |
warn "# $_\n" for @lines; |
| 39 |
}; |
| 40 |
$c->send_response($res); |
| 41 |
} |
| 42 |
$c->close; |
| 43 |
undef($c); |
| 44 |
}; |