This will allow others to mimic our award-winning homepage
design without needing to rely on Plack::Middleware::Deflater
or varnish to compress responses.
use HTTP::Status qw(status_message);
use Errno qw(EACCES ENOTDIR ENOENT);
use URI::Escape qw(uri_escape_utf8);
use HTTP::Status qw(status_message);
use Errno qw(EACCES ENOTDIR ENOENT);
use URI::Escape qw(uri_escape_utf8);
+use PublicInbox::NoopFilter;
+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);
use PublicInbox::Hval qw(ascii_html);
use Plack::MIME;
our @EXPORT_OK = qw(@NO_CACHE r path_info_raw);
(map { ${$other{$_}} } sort keys %other));
my $path_info_html = ascii_html($path_info);
(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) || PublicInbox::NoopFilter::new();
+ $gzf->zmore("<html><head><title>Index of $path_info_html</title>" .
- "</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
}
sub call { # PSGI app endpoint
use PublicInbox::TestCommon;
my ($tmpdir, $for_destroy) = tmpdir();
my @mods = qw(HTTP::Request::Common Plack::Test URI::Escape);
use PublicInbox::TestCommon;
my ($tmpdir, $for_destroy) = tmpdir();
my @mods = qw(HTTP::Request::Common Plack::Test URI::Escape);
+require_mods(@mods, 'IO::Uncompress::Gunzip');
use_ok $_ foreach @mods;
use_ok 'PublicInbox::WwwStatic';
use_ok $_ foreach @mods;
use_ok 'PublicInbox::WwwStatic';
$get->header('Accept-Encoding' => 'gzip');
$res = $cb->($get);
is($res->content, "hi", 'got compressed on mtime match');
$get->header('Accept-Encoding' => 'gzip');
$res = $cb->($get);
is($res->content, "hi", 'got compressed on mtime match');
+
+ $get = GET('/dir/');
+ $get->header('Accept-Encoding' => 'gzip');
+ $res = $cb->($get);
+ my $in = $res->content;
+ my $out = '';
+ IO::Uncompress::Gunzip::gunzip(\$in => \$out);
+ like($out, qr/\A<html>/, 'got HTML start after gunzip');
+ like($out, qr{</html>$}, 'got HTML end after gunzip');