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.7 by root, Sat May 17 21:08:05 2008 UTC vs.
Revision 1.11 by root, Fri Jul 24 22:47:04 2009 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines