X-Git-Url: http://www.git.stargrave.org/?a=blobdiff_plain;f=t%2Fcommon.perl;h=1251333d8a7145f4f80b983a5a2705e8ef34f044;hb=95d4bf7aded41cb3b0040c321d315532f68633e1;hp=bec57699de226ffa7405c1cdedcbc4c567219bec;hpb=21f5b7a8bcd942b19475c1c0c265f39dfdf93608;p=public-inbox.git diff --git a/t/common.perl b/t/common.perl index bec57699..1251333d 100644 --- a/t/common.perl +++ b/t/common.perl @@ -1,18 +1,15 @@ # Copyright (C) 2015 all contributors # License: AGPLv3 or later (https://www.gnu.org/licenses/agpl-3.0.txt) -require IO::File; -use POSIX qw/dup/; 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;