Debian Codegraph @

samples/delayed_example

raw
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 my $timer;
11 $httpd->reg_cb (
12 '' => sub {
13 my ($httpd, $req) = @_;
14
15 $req->respond ({ content => [ 'text/html',
16 "<html><body><h1>Testing return types...</h1>"
17 . "<img src=\"/image/bshttp.png\" />"
18 . "</body></html>"
19 ]});
20 },
21 '/image/bshttp.png' => sub {
22 my ($httpd, $req) = @_;
23 $httpd->stop_request;
24
25 $timer = AnyEvent->timer (after => 3, cb => sub {
26 open IMG, 'bshttp.png' or do { $req->respond; return }; # respond without output will
27 # generate a 404
28 $req->respond ({ content => [ 'image/png', do { local $/; <IMG> } ] });
29 });
30 },
31 );
32
33 $cvar->wait;