ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/AnyEvent/t/handle/03_http_req.t
Revision: 1.2
Committed: Sun Apr 27 19:15:43 2008 UTC (16 years, 2 months ago) by elmex
Content type: application/x-troff
Branch: MAIN
Changes since 1.1: +8 -1 lines
Log Message:
updated documentation and changelog and made the http test optional

File Contents

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