--- AnyEvent/t/handle/03_http_req.t 2008/05/24 23:15:14 1.10 +++ AnyEvent/t/handle/03_http_req.t 2009/07/24 22:47:04 1.11 @@ -18,49 +18,43 @@ my $rbytes; -my $hdl; -my $wo = tcp_connect 'www.google.com', 80, sub { - my ($fh) = @_; - - $hdl = - AnyEvent::Handle->new ( - fh => $fh, - on_error => sub { - warn "socket error: $!"; - $cv->broadcast; - }, - on_eof => sub { - my ($hdl) = @_; - - if ($rbytes !~ /<\/html>/i) { - print "not "; - } - - print "ok 2 - received HTML page\n"; +my $hdl; $hdl = + AnyEvent::Handle->new ( + connect => ['www.google.com', 80], + on_error => sub { + warn "socket error: $!"; + $cv->broadcast; + }, + on_eof => sub { + my ($hdl) = @_; - $cv->broadcast + if ($rbytes !~ /<\/html>/i) { + print "not "; } - ); - $hdl->push_read (chunk => 10, sub { - my ($hdl, $data) = @_; + print "ok 2 - received HTML page\n"; - unless (substr ($data, 0, 4) eq 'HTTP') { - print "not "; + $cv->broadcast; } + ); - print "ok 1 - received 'HTTP'\n"; +$hdl->push_read (chunk => 10, sub { + my ($hdl, $data) = @_; - $hdl->on_read (sub { - my ($hdl) = @_; - $rbytes .= $hdl->rbuf; - $hdl->rbuf = ''; - return 1; - }); + unless (substr ($data, 0, 4) eq 'HTTP') { + print "not "; + } + + print "ok 1 - received 'HTTP'\n"; + + $hdl->on_read (sub { + my ($hdl) = @_; + $rbytes .= $hdl->rbuf; + $hdl->rbuf = ''; + return 1; }); +}); - $hdl->push_write ("GET http://www.google.com/ HTTP/1.0\015\012\015\012"); - -}; +$hdl->push_write ("GET http://www.google.com/ HTTP/1.0\015\012\015\012"); $cv->wait;