X-Git-Url: http://www.git.stargrave.org/?a=blobdiff_plain;f=t%2Fcommon.perl;h=5c5fcd84890dbef23a07c2529c28b8341acc6bd7;hb=4db4bfa2c9178b315d2ac09cff794a4476ba1f6e;hp=a3585bf692dd7c5f35dc420dc48fa186a144a967;hpb=1761fba7befab2681276ac8f123593610ad27e58;p=public-inbox.git diff --git a/t/common.perl b/t/common.perl index a3585bf6..5c5fcd84 100644 --- a/t/common.perl +++ b/t/common.perl @@ -1,16 +1,15 @@ -require IO::File; -use POSIX qw/dup/; +# Copyright (C) 2015-2018 all contributors +# License: AGPL-3.0+ sub stream_to_string { - my ($cb) = @_; - my $headers; - my $io = IO::File->new_tmpfile; - my $dup = dup($io->fileno); - my $response = sub { $headers = \@_, $io }; - $cb->($response); - $io = IO::File->new; - $io->fdopen($dup, 'r+'); - $io->seek(0, 0); - $io->read(my $str, ($io->stat)[7]); + my ($res) = @_; + my $body = $res->[2]; + my $str = ''; + while (defined(my $chunk = $body->getline)) { + $str .= $chunk; + } + $body->close; $str; } + +1;