Merge branch 'master' of ssh://elmex@rain/~/pubrep/AnyEvent-HTTPD
[AnyEvent-HTTPD.git] / samples / second_example
blob0fadaf88e294c454d387c668235a58cf12d40904
1 #!/opt/perl/bin/perl
2 use AnyEvent;
3 use AnyEvent::HTTPD;
5 my $cvar = AnyEvent->condvar;
7 my $httpd = AnyEvent::HTTPD->new (port => 19090);
9 $httpd->reg_cb (
10 '' => sub {
11 my ($httpd, $req) = @_;
13 $req->respond ({ content => [ 'text/html',
14 "<html><body><h1>Testing return types...</h1>"
15 . "<img src=\"/image/bshttp.png\" />"
16 . "</body></html>"
17 ]});
19 '/image/bshttp.png' => sub {
20 $_[0]->stop_request;
22 open IMG, 'bshttp.png'
23 or do { $_[1]->respond (
24 [404, 'not found', { 'Content-Type' => 'text/plain' }, 'Fail!']);
25 return };
26 $_[1]->respond ({ content => [ 'image/png', do { local $/; <IMG> } ] });
30 $cvar->wait;