~ubuntu-branches/ubuntu/trusty/libanyevent-httpd-perl/trusty

« back to all changes in this revision

Viewing changes to samples/delayed_example

  • Committer: Package Import Robot
  • Author(s): Dmitry E. Oboukhov
  • Date: 2011-11-19 01:05:06 UTC
  • Revision ID: package-import@ubuntu.com-20111119010506-7l2vrh0in6744zba
Tags: upstream-0.93
ImportĀ upstreamĀ versionĀ 0.93

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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;