use PublicInbox::Linkify;
use PublicInbox::View;
use PublicInbox::Inbox;
-use bytes ();
+use PublicInbox::NoopFilter;
+use PublicInbox::GzipFilter qw(gzf_maybe);
+use bytes (); # bytes::length
use HTTP::Date qw(time2str);
use Digest::SHA ();
use File::Spec ();
+use IO::Compress::Gzip qw(gzip);
*try_cat = \&PublicInbox::Inbox::try_cat;
+our $json;
+for my $mod (qw(JSON::MaybeXS JSON JSON::PP)) {
+ eval "require $mod" or next;
+ # ->ascii encodes non-ASCII to "\uXXXX"
+ $json = $mod->new->ascii(1) and last;
+}
sub list_all_i {
my ($ibx, $arg) = @_;
sub html ($$) {
my ($env, $list) = @_;
- my $title = 'public-inbox';
- my $out = '';
+ my $h = [ 'Content-Type', 'text/html; charset=UTF-8',
+ 'Content-Length', undef ];
+ my $gzf = gzf_maybe($h, $env) || PublicInbox::NoopFilter::new();
+ my $out = $gzf->zmore('<html><head><title>' .
+ 'public-inbox listing</title>' .
+ '</head><body><pre>');
my $code = 404;
if (@$list) {
- $title .= ' - listing';
$code = 200;
-
# Schwartzian transform since Inbox->modified is expensive
@$list = sort {
$b->[0] <=> $a->[0]
my $tmp = join("\n", map { ibx_entry(@$_, $env) } @$list);
my $l = PublicInbox::Linkify->new;
- $out = '<pre>'.$l->to_html($tmp).'</pre><hr>';
+ $out .= $gzf->zmore($l->to_html($tmp));
+ } else {
+ $out .= $gzf->zmore('no inboxes, yet');
}
- $out = "<html><head><title>$title</title></head><body>" . $out;
- $out .= '<pre>'. PublicInbox::WwwStream::code_footer($env) .
- '</pre></body></html>';
-
- my $h = [ 'Content-Type', 'text/html; charset=UTF-8' ];
+ $out .= $gzf->zflush('</pre><hr><pre>'.
+ PublicInbox::WwwStream::code_footer($env) .
+ '</pre></body></html>');
+ $h->[3] = bytes::length($out);
[ $code, $h, [ $out ] ];
}
-my $json;
-sub _json () {
- for my $mod (qw(JSON::MaybeXS JSON JSON::PP)) {
- eval "require $mod" or next;
- # ->ascii encodes non-ASCII to "\uXXXX"
- return $mod->new->ascii(1);
- }
- die;
-}
-
sub fingerprint ($) {
my ($git) = @_;
# TODO: convert to qspawn for fairness when there's
chomp(my $owner = $git->qx('config', 'gitweb.owner'));
chomp(my $desc = try_cat("$git_dir/description"));
+ utf8::decode($owner);
+ utf8::decode($desc);
$owner = undef if $owner eq '';
$desc = 'Unnamed repository' if $desc eq '';
# manifest.js.gz
sub js ($$) {
my ($env, $list) = @_;
- eval { require IO::Compress::Gzip } or return [ 404, [], [] ];
+ # $json won't be defined if IO::Compress::Gzip is missing
+ $json or return [ 404, [], [] ];
my $manifest = { -abs2urlpath => {}, -mtime => 0 };
for my $ibx (@$list) {
$repo->{reference} = $abs2urlpath->{$abs};
}
my $out;
- IO::Compress::Gzip::gzip(\(($json ||= _json())->encode($manifest)) =>
- \$out);
+ gzip(\($json->encode($manifest)) => \$out);
$manifest = undef;
[ 200, [ qw(Content-Type application/gzip),
'Last-Modified', time2str($mtime),