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.10 by root, Sat May 24 23:15:14 2008 UTC vs.
Revision 1.11 by root, Fri Jul 24 22:47:04 2009 UTC

16 16
17my $cv = AnyEvent->condvar; 17my $cv = AnyEvent->condvar;
18 18
19my $rbytes; 19my $rbytes;
20 20
21my $hdl; 21my $hdl; $hdl =
22my $wo = tcp_connect 'www.google.com', 80, sub { 22 AnyEvent::Handle->new (
23 connect => ['www.google.com', 80],
24 on_error => sub {
25 warn "socket error: $!";
26 $cv->broadcast;
27 },
28 on_eof => sub {
23 my ($fh) = @_; 29 my ($hdl) = @_;
24 30
25 $hdl = 31 if ($rbytes !~ /<\/html>/i) {
26 AnyEvent::Handle->new ( 32 print "not ";
27 fh => $fh,
28 on_error => sub {
29 warn "socket error: $!";
30 $cv->broadcast;
31 }, 33 }
32 on_eof => sub {
33 my ($hdl) = @_;
34 34
35 if ($rbytes !~ /<\/html>/i) { 35 print "ok 2 - received HTML page\n";
36 print "not ";
37 }
38 36
39 print "ok 2 - received HTML page\n"; 37 $cv->broadcast;
38 }
39 );
40 40
41 $cv->broadcast 41$hdl->push_read (chunk => 10, sub {
42 } 42 my ($hdl, $data) = @_;
43 );
44 43
45 $hdl->push_read (chunk => 10, sub { 44 unless (substr ($data, 0, 4) eq 'HTTP') {
46 my ($hdl, $data) = @_; 45 print "not ";
46 }
47 47
48 unless (substr ($data, 0, 4) eq 'HTTP') { 48 print "ok 1 - received 'HTTP'\n";
49 print "not ";
50 }
51 49
52 print "ok 1 - received 'HTTP'\n"; 50 $hdl->on_read (sub {
51 my ($hdl) = @_;
52 $rbytes .= $hdl->rbuf;
53 $hdl->rbuf = '';
54 return 1;
55 });
56});
53 57
54 $hdl->on_read (sub {
55 my ($hdl) = @_;
56 $rbytes .= $hdl->rbuf;
57 $hdl->rbuf = '';
58 return 1;
59 });
60 });
61
62 $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");
63
64};
65 59
66$cv->wait; 60$cv->wait;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines