ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/AnyEvent/t/handle/03_http_req.t
Revision: 1.7
Committed: Sat May 17 21:08:05 2008 UTC (16 years, 1 month ago) by root
Content type: application/x-troff
Branch: MAIN
CVS Tags: rel-3_5
Changes since 1.6: +5 -5 lines
Log Message:
*** empty log message ***

File Contents

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