rewrite, with a request object everything becomes easier
[AnyEvent-HTTPD.git] / samples / second_example
blobd7a370da692425e281312d070cadd591f2c045e4
1 #!/opt/perl/bin/perl
2 use AnyEvent;
3 use BS::HTTPD;
5 my $cvar = AnyEvent->condvar;
7 my $httpd = BS::HTTPD->new (port => 9090);
9 $httpd->reg_cb (
10 _ => sub {
11 my ($httpd, $req) = @_;
13 $req->o ("<html><body><h1>Testing return types...</h1>");
14 $req->o ("<img src=\"/image/bshttp.png\" />");
15 $req->o ("</body></html>");
16 $req->respond;
18 '_image_bshttp.png' => sub {
19 open IMG, 'bshttp.png'
20 or do { $_[1]->respond (
21 [404, 'not found', { 'Content-Type' => 'text/plain' }, 'Fail!']);
22 return };
23 $_[1]->respond ({ content => [ 'image/png', do { local $/; <IMG> } ] });
27 $cvar->wait;