From 8a3fc4a2f027b36f27225ceee5908c571c8f4f47 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Sat, 4 Mar 2017 03:52:29 +0000 Subject: repoobrowse: explicit EOF handling for git async callback We need to ensure we've fully-drained the pipe before signalling EOF to the callback, since pipelining may not be the best choice with detachable processes in the future. --- lib/PublicInbox/RepoGitRaw.pm | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) (limited to 'lib/PublicInbox/RepoGitRaw.pm') diff --git a/lib/PublicInbox/RepoGitRaw.pm b/lib/PublicInbox/RepoGitRaw.pm index 858034a3..717ca71f 100644 --- a/lib/PublicInbox/RepoGitRaw.pm +++ b/lib/PublicInbox/RepoGitRaw.pm @@ -36,15 +36,17 @@ sub git_raw_check_res ($$$) { my $buf = ''; $req->{-repo}->{git}->cat_async($req->{env}, $hex, sub { my ($r) = @_; - return if ref($r) ne 'SCALAR'; - $buf .= $$r; - return if bytes::length($buf) < $size; - $ct ||= index($buf, "\0") >= 0 ? - 'application/octet-stream' : - 'text/plain; charset=UTF-8'; - $res->([200, ['Content-Type', $ct, - 'Content-Length', $size ], - [ $buf ]]); + if (ref($r) eq 'SCALAR') { + $buf .= $$r; + } elsif ($r == 0) { + return if bytes::length($buf) < $size; + $ct ||= index($buf, "\0") >= 0 ? + 'application/octet-stream' : + 'text/plain; charset=UTF-8'; + $res->([200, ['Content-Type', $ct, + 'Content-Length', $size ], + [ $buf ]]); + } }); } } -- cgit v1.2.3-24-ge0c7