X-Git-Url: http://www.git.stargrave.org/?a=blobdiff_plain;f=t%2Fcommon.perl;h=5c5fcd84890dbef23a07c2529c28b8341acc6bd7;hb=4790a0dbd7b297e087713c6ff2e63bf7deee4d04;hp=bec57699de226ffa7405c1cdedcbc4c567219bec;hpb=f76f265a851944b5dedcc3be5f3b5224b6ebda89;p=public-inbox.git
diff --git a/t/common.perl b/t/common.perl
index bec57699..5c5fcd84 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/;
+# 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;