ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/AnyEvent/t/handle/03_http_req.t
Revision: 1.3
Committed: Sun Apr 27 19:36:55 2008 UTC (16 years, 2 months ago) by root
Content type: application/x-troff
Branch: MAIN
Changes since 1.2: +2 -0 lines
Log Message:
*** empty log message ***

File Contents

# Content
1 #!/opt/perl/bin/perl
2
3 use strict;
4 use Test::More;
5 use AnyEvent::Impl::Perl;
6 use AnyEvent;
7 use AnyEvent::Socket;
8
9 unless ($ENV{PERL_ANYEVENT_NET_TESTS}) {
10 plan skip_all => "PERL_ANYEVENT_NET_TESTS environment variable not set";
11 exit 0;
12 }
13
14 plan tests => 2;
15
16 my $cv = AnyEvent->condvar;
17
18 my $fbytes;
19 my $rbytes;
20
21 my $ae_sock =
22 AnyEvent::Socket->new (
23 PeerAddr => "www.google.de:80",
24 on_eof => sub { $cv->broadcast },
25 on_error => sub {
26 my ($ae_sock) = @_;
27 diag "error: $!";
28 $cv->broadcast
29 },
30 on_connect => sub {
31 my ($ae_sock, $error) = @_;
32 if ($error) { diag ("connect error: $!"); return }
33
34 $ae_sock->read (10, sub {
35 my ($ae_sock, $data) = @_;
36 $fbytes = $data;
37
38 $ae_sock->on_read (sub {
39 my ($ae_sock) = @_;
40 $rbytes = $ae_sock->rbuf;
41 });
42 });
43
44 $ae_sock->write ("GET http://www.google.de/ HTTP/1.0\015\012\015\012");
45 }
46 );
47
48 $cv->wait;
49
50 is (substr ($fbytes, 0, 4), 'HTTP', 'first bytes began with HTTP');
51 ok ($rbytes =~ /google.*<\/html>\s*$/i, 'content was retrieved successfully');