From 95d4bf7aded41cb3b0040c321d315532f68633e1 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Sat, 3 Dec 2016 00:24:06 +0000 Subject: atom: switch to getline/close for response bodies 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. --- t/common.perl | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) (limited to 't') 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; -- cgit v1.2.3-24-ge0c7