AnyEvent-HTTPD

 view release on metacpan or  search on metacpan

lib/AnyEvent/HTTPD/HTTPConnection.pm  view on Meta::CPAN

}

sub push_header_line {
   my ($self) = @_;

   return if $self->{disconnected};

   weaken $self;

   $self->{req_timeout} =
      AnyEvent->timer (after => $self->{request_timeout}, cb => sub {
         return unless defined $self;

         $self->do_disconnect ("request timeout ($self->{request_timeout})");
      });

   $self->{hdl}->push_read (line => sub {
      my ($hdl, $line) = @_;
      return unless defined $self;

      delete $self->{req_timeout};

lib/AnyEvent/HTTPD/HTTPConnection.pm  view on Meta::CPAN

   return if $self->{disconnected};

   $self->{disconnected} = 1;
   $self->{transfer_cb}->() if $self->{transfer_cb};
   delete $self->{transfer_cb};
   delete $self->{req_timeout};
   $self->event ('disconnect', $err);
   shutdown $self->{hdl}->{fh}, 1;
   $self->{hdl}->on_read (sub { });
   $self->{hdl}->on_eof (undef);
   my $timer;
   $timer = AE::timer 2, 0, sub {
      undef $timer;
      delete $self->{hdl};
   };
}

1;

lib/AnyEvent/HTTPD/Util.pm  view on Meta::CPAN

      push @{$cont->{$name}}, [$val, ''];
   }
   $cont
}

sub test_connect {
   my ($host, $port, $data) = @_;

   my $c = AE::cv;

   my $t; $t = AnyEvent->timer (after => 0.1, cb => sub {
      my $hdl;
      my $buf;
      undef $t;
      tcp_connect $host, $port, sub {
         my ($fh) = @_
            or die "couldn't connect: $!";

         $hdl =
            AnyEvent::Handle->new (
               fh => $fh,

samples/delayed_2_example  view on Meta::CPAN

         "<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;

samples/delayed_example  view on Meta::CPAN

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

my $cvar = AnyEvent->condvar;

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

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

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

      $timer = AnyEvent->timer (after => 3, cb => sub {
         open IMG, 'bshttp.png' or do { $req->respond; return }; # respond without output will
                                                                 # generate a 404
         $req->respond ({ content => [ 'image/png', do { local $/; <IMG> } ] });
      });
   },
);

$cvar->wait;



( run in 1.205 second using v1.01-cache-2.11-cpan-49f99fa48dc )