]> Sergey Matveev's repositories - public-inbox.git/blobdiff - t/common.perl
public-inbox 1.1.0-pre1
[public-inbox.git] / t / common.perl
index a3585bf692dd7c5f35dc420dc48fa186a144a967..5c5fcd84890dbef23a07c2529c28b8341acc6bd7 100644 (file)
@@ -1,16 +1,15 @@
-require IO::File;
-use POSIX qw/dup/;
+# Copyright (C) 2015-2018 all contributors <meta@public-inbox.org>
+# License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
 
 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;