AnyEvent-HTTP-MXHR
view release on metacpan or search on metacpan
lib/AnyEvent/HTTP/MXHR.pm view on Meta::CPAN
Carp::confess("@_");
};
my $on_eof = delete $args{on_eof} || sub { };
my %state;
$state{guard} = http_get $uri, %args,
want_body_handle => 1,
on_error => $on_error,
on_header => sub {
my ($headers) = @_;
if ($headers->{"content-type"} =~ m{^multipart/mixed\s*;\s*boundary="([^"]+)"}) {
$state{boundary} = $1;
$state{boundary_re} = qr!(?:^|\r?\n)--$state{boundary}\n?!;
return 1;
} else {
%state = ();
$on_error->("Header not found");
return ();
}
},
sub {
t/001_basic.t view on Meta::CPAN
my $cv = AE::cv { undef $guard };
my $quit = sub {
$cv->send();
};
$guard = mxhr_get "http://127.0.0.1:$port",
on_error => $quit,
on_eof => $quit,
sub {
my ($body, $headers) = @_;
if ($headers->{'content-type'} =~ /^application\/json/) {
ok(1, "json received");
my $json = eval { decode_json $body };
ok ($json, "JSON decoded OK");
ok ($json->{seq} <= $seq, "seq ok $seq");
if ($seq == $json->{seq}) { $seq++ } # see above XXX
} else {
ok(0, "unknown content-type: $headers->{'content-type'}");
ok(0, "don't know how to handle data");
ok(0, "don't know how to get seq");
$seq++;
}
if($seq > 10) {
$quit->();
return;
}
return 1;
( run in 3.660 seconds using v1.01-cache-2.11-cpan-524268b4103 )