about summary refs log tree commit homepage
path: root/t
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2016-12-03 00:24:06 +0000
committerEric Wong <e@80x24.org>2016-12-03 01:48:14 +0000
commit95d4bf7aded41cb3b0040c321d315532f68633e1 (patch)
treeb971609ef6fd3665d7d68352600d22ffe5b05cf8 /t
parent21f5b7a8bcd942b19475c1c0c265f39dfdf93608 (diff)
downloadpublic-inbox-95d4bf7aded41cb3b0040c321d315532f68633e1.tar.gz
This will let us stream larger Atom documents bodies without
wasting too much memory and reduce the amount of round-trip
requests needed to get necessary information.

Hopefully clients are using streaming (SAX) parsers, too.

This is the final transition in the core public-inbox
code to allow migrating to a "pull"-based body streaming
scheme which allows a HTTP server to respond appropriately
to backpressure from slow clients.
Diffstat (limited to 't')
-rw-r--r--t/common.perl21
1 files changed, 9 insertions, 12 deletions
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 <meta@public-inbox.org>
 # 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;