ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/AnyEvent/t/handle/03_http_req.t
Revision: 1.6
Committed: Thu May 15 14:12:24 2008 UTC (16 years, 1 month ago) by elmex
Content type: application/x-troff
Branch: MAIN
Changes since 1.5: +45 -32 lines
Log Message:
fixed http request test

File Contents

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