ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/AnyEvent/t/handle/03_http_req.t
Revision: 1.9
Committed: Fri May 23 17:50:15 2008 UTC (16 years, 1 month ago) by root
Content type: application/x-troff
Branch: MAIN
CVS Tags: rel-4_0
Changes since 1.8: +3 -2 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.8 use AnyEvent::Socket;
8 root 1.7 use AnyEvent::Handle;
9 elmex 1.1
10 elmex 1.2 unless ($ENV{PERL_ANYEVENT_NET_TESTS}) {
11 elmex 1.6 print "1..0 # Skip PERL_ANYEVENT_NET_TESTS environment variable not set\n";
12 elmex 1.2 exit 0;
13     }
14    
15 elmex 1.6 print "1..2\n";
16 elmex 1.2
17 elmex 1.1 my $cv = AnyEvent->condvar;
18    
19     my $rbytes;
20    
21 elmex 1.6 my $hdl;
22 root 1.8 my $wo = tcp_connect 'www.google.com', 80, sub {
23 root 1.9 my ($fh) = @_;
24    
25 elmex 1.6 $hdl =
26     AnyEvent::Handle->new (
27 root 1.9 fh => $fh,
28 elmex 1.6 on_error => sub {
29     warn "socket error: $!";
30     $cv->broadcast;
31     },
32     on_eof => sub {
33     my ($hdl) = @_;
34    
35     if ($rbytes !~ /<\/html>/i) {
36     print "not ";
37     }
38    
39     print "ok 2 - received HTML page\n";
40    
41     $cv->broadcast
42     }
43     );
44    
45     $hdl->push_read_chunk (10, sub {
46     my ($hdl, $data) = @_;
47 elmex 1.1
48 elmex 1.6 unless (substr ($data, 0, 4) eq 'HTTP') {
49     print "not ";
50 elmex 1.1 }
51 elmex 1.6
52     print "ok 1 - received 'HTTP'\n";
53    
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");
63    
64 root 1.7 };
65 elmex 1.1
66     $cv->wait;