| 1 |
#!/opt/perl/bin/perl |
| 2 |
use common::sense; |
| 3 |
use AnyEvent; |
| 4 |
use AnyEvent::HTTPD; |
| 5 |
|
| 6 |
my $cvar = AnyEvent->condvar; |
| 7 |
|
| 8 |
my $httpd = AnyEvent::HTTPD->new (port => 19090); |
| 9 |
|
| 10 |
$httpd->reg_cb ( |
| 11 |
'' => sub { |
| 12 |
my ($httpd, $req) = @_; |
| 13 |
|
| 14 |
$req->respond ({ content => [ 'text/html', |
| 15 |
"<html><body><h1>Testing return types...</h1>" |
| 16 |
. "<img src=\"/image/bshttp.png\" />" |
| 17 |
. "</body></html>" |
| 18 |
]}); |
| 19 |
}, |
| 20 |
'/image/bshttp.png' => sub { |
| 21 |
$_[0]->stop_request; |
| 22 |
|
| 23 |
open IMG, 'bshttp.png' |
| 24 |
or do { $_[1]->respond ( |
| 25 |
[404, 'not found', { 'Content-Type' => 'text/plain' }, 'Fail!']); |
| 26 |
return }; |
| 27 |
$_[1]->respond ({ content => [ 'image/png', do { local $/; <IMG> } ] }); |
| 28 |
}, |
| 29 |
); |
| 30 |
|
| 31 |
$cvar->wait; |