use parent qw(Exporter);
require List::Util;
-our @EXPORT_OK = qw(uniqstr);
+our @EXPORT_OK = qw(uniqstr sum0);
# uniqstr is in List::Util 1.45+, which means Perl 5.26+;
# so maybe 2030 for us since we need to support enterprise distros.
grep { !$seen{$_}++ } @_;
};
+*sum0 = List::Util->can('sum0') // sub (@) { List::Util::sum(@_) // 0 };
+
1;
package PublicInbox::HTTP;
use strict;
use parent qw(PublicInbox::DS);
+use bytes qw(length);
use Fcntl qw(:seek);
use Plack::HTTPParser qw(parse_http_request); # XS or pure Perl
use Plack::Util;
CHUNK_MAX_HDR => 256,
};
use Errno qw(EAGAIN);
+use PublicInbox::Compat qw(sum0);
# Use the same configuration parameter as git since this is primarily
# a slow-client sponge for git-http-backend
}
}
-sub response_header_write {
+sub response_header_write ($$$) {
my ($self, $env, $res) = @_;
my $proto = $env->{SERVER_PROTOCOL} or return; # HTTP/0.9 :P
my $status = $res->[0];
my $term = defined($len) || $chunked;
my $prot_persist = ($proto eq 'HTTP/1.1') && ($conn !~ /\bclose\b/i);
my $alive;
+ if (!$term && ref($res->[2]) eq 'ARRAY') {
+ $len = sum0(map length, @{$res->[2]});
+ $h .= "Content-Length: $len\r\n";
+ $term = 1;
+ }
if (!$term && $prot_persist) { # auto-chunk
$chunked = $alive = 2;
$alive = 3 if $env->{REQUEST_METHOD} eq 'HEAD';
sub write {
# ([$http], $buf) = @_;
PublicInbox::HTTP::chunked_write($_[0]->[0], $_[1]);
- $_[0]->[0]->{sock} ? length($_[1]) : undef;
+ $_[0]->[0]->{sock} ? bytes::length($_[1]) : undef;
}
sub close {
sub write {
# ([$http], $buf) = @_;
PublicInbox::HTTP::identity_write($_[0]->[0], $_[1]);
- $_[0]->[0]->{sock} ? length($_[1]) : undef;
+ $_[0]->[0]->{sock} ? bytes::length($_[1]) : undef;
}
1;