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.8 by root, Fri May 23 17:47:06 2008 UTC vs.
Revision 1.13 by root, Thu Apr 5 06:14:10 2012 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines