ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/AnyEvent/t/handle/03_http_req.t
Revision: 1.1
Committed: Sun Apr 27 16:56:17 2008 UTC (16 years, 2 months ago) by elmex
Content type: application/x-troff
Branch: MAIN
Log Message:
added IO::AnyEvent as AnyEvent::Handle and AnyEvent::Socket, including tests

File Contents

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