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

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