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

# Content
1 #!/opt/perl/bin/perl
2
3 use strict;
4
5 use AnyEvent::Impl::Perl;
6 use AnyEvent;
7 use AnyEvent::Handle;
8
9 unless ($ENV{PERL_ANYEVENT_NET_TESTS}) {
10 print "1..0 # Skip PERL_ANYEVENT_NET_TESTS environment variable not set\n";
11 exit 0;
12 }
13
14 print "1..2\n";
15
16 my $cv = AnyEvent->condvar;
17
18 my $rbytes;
19
20 my $hdl;
21 my $wo = AnyEvent::Util::tcp_connect 'www.google.com', 80, sub {
22 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
46 unless (substr ($data, 0, 4) eq 'HTTP') {
47 print "not ";
48 }
49
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 };
63
64 $cv->wait;