ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/AnyEvent/t/handle/03_http_req.t
Revision: 1.8
Committed: Fri May 23 17:47:06 2008 UTC (16 years, 1 month ago) by root
Content type: application/x-troff
Branch: MAIN
Changes since 1.7: +2 -1 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 ($sock) = @_;
24 $hdl =
25 AnyEvent::Handle->new (
26 fh => $sock,
27 on_error => sub {
28 warn "socket error: $!";
29 $cv->broadcast;
30 },
31 on_eof => sub {
32 my ($hdl) = @_;
33
34 if ($rbytes !~ /<\/html>/i) {
35 print "not ";
36 }
37
38 print "ok 2 - received HTML page\n";
39
40 $cv->broadcast
41 }
42 );
43
44 $hdl->push_read_chunk (10, sub {
45 my ($hdl, $data) = @_;
46
47 unless (substr ($data, 0, 4) eq 'HTTP') {
48 print "not ";
49 }
50
51 print "ok 1 - received 'HTTP'\n";
52
53 $hdl->on_read (sub {
54 my ($hdl) = @_;
55 $rbytes .= $hdl->rbuf;
56 $hdl->rbuf = '';
57 return 1;
58 });
59 });
60
61 $hdl->push_write ("GET http://www.google.com/ HTTP/1.0\015\012\015\012");
62
63 };
64
65 $cv->wait;