#!/opt/perl/bin/perl
use AnyEvent;
use AnyEvent::HTTPD;

my $cvar = AnyEvent->condvar;

my $httpd = AnyEvent::HTTPD->new (port => 9090);

$httpd->reg_cb (
   '' => sub {
      my ($httpd, $req) = @_;

      $req->o ("<html><body><h1>Testing return types...</h1>");
      $req->o ("<img src=\"/image/bshttp.png\" />");
      $req->o ("</body></html>");
      $req->respond;
   },
   '/image/bshttp.png' => sub {
      $_[0]->stop_request;

      open IMG, 'bshttp.png'
         or do { $_[1]->respond (
                    [404, 'not found', { 'Content-Type' => 'text/plain' }, 'Fail!']);
                    return };
      $_[1]->respond ({ content => [ 'image/png', do { local $/; <IMG> } ] });
   },
);

$cvar->wait;
