ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/AnyEvent/t/handle/03_http_req.t
(Generate patch)

Comparing AnyEvent/t/handle/03_http_req.t (file contents):
Revision 1.6 by elmex, Thu May 15 14:12:24 2008 UTC vs.
Revision 1.12 by root, Wed Dec 29 04:16:35 2010 UTC

1#!/opt/perl/bin/perl 1#!/opt/perl/bin/perl
2
2use strict; 3use strict;
3use AnyEvent::Impl::Perl; 4
4use AnyEvent; 5use AnyEvent;
6BEGIN { require AnyEvent::Impl::Perl unless $ENV{PERL_ANYEVENT_MODEL} }
5use AnyEvent::Socket; 7use AnyEvent::Socket;
8use AnyEvent::Handle;
6 9
7unless ($ENV{PERL_ANYEVENT_NET_TESTS}) { 10unless ($ENV{PERL_ANYEVENT_NET_TESTS}) {
8 print "1..0 # Skip PERL_ANYEVENT_NET_TESTS environment variable not set\n"; 11 print "1..0 # Skip PERL_ANYEVENT_NET_TESTS environment variable not set\n";
9 exit 0; 12 exit 0;
10} 13}
13 16
14my $cv = AnyEvent->condvar; 17my $cv = AnyEvent->condvar;
15 18
16my $rbytes; 19my $rbytes;
17 20
18my $hdl; 21my $hdl; $hdl =
19my $wo = AnyEvent::Util::tcp_connect ('www.google.com', 80, sub {
20 my ($sock) = @_;
21 $hdl =
22 AnyEvent::Handle->new ( 22 AnyEvent::Handle->new (
23 fh => $sock, 23 connect => ['www.google.com', 80],
24 on_error => sub { 24 on_error => sub {
25 warn "socket error: $!"; 25 warn "socket error: $!";
26 $cv->broadcast; 26 $cv->broadcast;
27 }, 27 },
28 on_eof => sub { 28 on_eof => sub {
29 my ($hdl) = @_; 29 my ($hdl) = @_;
30 30
31 if ($rbytes !~ /<\/html>/i) { 31 if ($rbytes !~ /<\/html>/i) {
32 print "not "; 32 print "not ";
33 } 33 }
34 34
35 print "ok 2 - received HTML page\n"; 35 print "ok 2 - received HTML page\n";
36 36
37 $cv->broadcast 37 $cv->broadcast;
38 } 38 }
39 ); 39 );
40 40
41 $hdl->push_read_chunk (10, sub { 41$hdl->push_read (chunk => 10, sub {
42 my ($hdl, $data) = @_; 42 my ($hdl, $data) = @_;
43 43
44 unless (substr ($data, 0, 4) eq 'HTTP') { 44 unless (substr ($data, 0, 4) eq 'HTTP') {
45 print "not "; 45 print "not ";
46 } 46 }
47 47
48 print "ok 1 - received 'HTTP'\n"; 48 print "ok 1 - received 'HTTP'\n";
49 49
50 $hdl->on_read (sub { 50 $hdl->on_read (sub {
51 my ($hdl) = @_; 51 my ($hdl) = @_;
52 $rbytes .= $hdl->rbuf; 52 $rbytes .= $hdl->rbuf;
53 $hdl->rbuf = ''; 53 $hdl->rbuf = '';
54 return 1; 54 return 1;
55 });
56 }); 55 });
56});
57 57
58 $hdl->push_write ("GET http://www.google.com/ HTTP/1.0\015\012\015\012"); 58$hdl->push_write ("GET http://www.google.com/ HTTP/1.0\015\012\015\012");
59
60}, sub {
61 warn "error on connect: $!";
62}, 10);
63 59
64$cv->wait; 60$cv->wait;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines