-# Copyright (C) 2016-2019 all contributors <meta@public-inbox.org>
+# Copyright (C) 2016-2021 all contributors <meta@public-inbox.org>
# License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
# This package can either be a PSGI response body for a static file
use HTTP::Status qw(status_message);
use Errno qw(EACCES ENOTDIR ENOENT);
use URI::Escape qw(uri_escape_utf8);
+use PublicInbox::GzipFilter qw(gzf_maybe);
use PublicInbox::Hval qw(ascii_html);
use Plack::MIME;
our @EXPORT_OK = qw(@NO_CACHE r path_info_raw);
return unless -f $gz && (stat(_))[9] == $mtime;
my $res = response($env, $h, $gz, $type);
return if ($res->[0] > 300 || $res->[0] < 200);
- push @{$res->[1]}, qw(Cache-Control no-transform Content-Encoding gzip);
+ push @{$res->[1]}, qw(Cache-Control no-transform
+ Content-Encoding gzip
+ Vary Accept-Encoding);
$res;
}
my $len = $self->{len} or return; # undef, tells server we're done
my $n = 8192;
$n = $len if $len < $n;
- seek($self->{in}, $self->{off}, SEEK_SET) or
- die "seek ($self->{path}): $!";
- my $r = read($self->{in}, my $buf, $n);
+ sysseek($self->{in}, $self->{off}, SEEK_SET) or
+ die "sysseek ($self->{path}): $!";
+ my $r = sysread($self->{in}, my $buf, $n);
if (defined $r && $r > 0) { # success!
$self->{len} = $len - $r;
$self->{off} += $r;
(map { ${$other{$_}} } sort keys %other));
my $path_info_html = ascii_html($path_info);
- my $body = "<html><head><title>Index of $path_info_html</title>" .
+ my $h = [qw(Content-Type text/html Content-Length), undef];
+ my $gzf = gzf_maybe($h, $env);
+ $gzf->zmore("<html><head><title>Index of $path_info_html</title>" .
${$self->{style}} .
- "</head><body><pre>Index of $path_info_html</pre><hr><pre>\n";
- $body .= join("\n", @entries) . "</pre><hr></body></html>\n";
- [ 200, [ qw(Content-Type text/html
- Content-Length), bytes::length($body) ], [ $body ] ]
+ "</head><body><pre>Index of $path_info_html</pre><hr><pre>\n");
+ $gzf->zmore(join("\n", @entries));
+ my $out = $gzf->zflush("</pre><hr></body></html>\n");
+ $h->[3] = bytes::length($out);
+ [ 200, $h, [ $out ] ]
}
sub call { # PSGI app endpoint