diff options
author | Eric Wong <e@yhbt.net> | 2020-07-05 23:27:27 +0000 |
---|---|---|
committer | Eric Wong <e@yhbt.net> | 2020-07-06 20:01:15 +0000 |
commit | 2bb3b3491416232a44ad8b318537c856cff727f4 (patch) | |
tree | aca8eb1c7a532d19727209dda335a8b2b5e8f552 /lib | |
parent | c2ae55ff47069952ac181111e83e550d7ff3c710 (diff) | |
download | public-inbox-2bb3b3491416232a44ad8b318537c856cff727f4.tar.gz |
This will allow others to mimic our award-winning homepage design without needing to rely on Plack::Middleware::Deflater or varnish to compress responses.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/PublicInbox/WwwStatic.pm | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/lib/PublicInbox/WwwStatic.pm b/lib/PublicInbox/WwwStatic.pm index 3c933156..d0611949 100644 --- a/lib/PublicInbox/WwwStatic.pm +++ b/lib/PublicInbox/WwwStatic.pm @@ -17,6 +17,8 @@ use HTTP::Date qw(time2str); 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); @@ -310,12 +312,15 @@ sub dir_response ($$$) { (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>" . ${$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 |