File: delayed_2_example

package info (click to toggle)
libanyevent-httpd-perl 0.93-6
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 244 kB
  • sloc: perl: 1,247; makefile: 4
file content (31 lines) | stat: -rwxr-xr-x 696 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#!/opt/perl/bin/perl
use common::sense;
use AnyEvent::HTTPD;

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

my $t;

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

      my $html =
         "<html><body><h1>Hello World!</h1>"
         . "<a href=\"/test\">another test page</a>"
         . "</body></html>";

      $req->respond ({ content => ['text/html', $html] });
   },
   '/test' => sub {
      my ($httpd, $req) = @_;
      $httpd->stop_request;

      $t = AnyEvent->timer (after => 2, cb => sub {
         my $txt = "CPU info:\n\n" . `cat /proc/cpuinfo`;
         $req->respond ([200, "ok", { 'Content-Type' => 'text/plain' }, $txt]);
      });
   },
);

$httpd->run;