X-Git-Url: http://www.git.stargrave.org/?p=public-inbox.git;a=blobdiff_plain;f=lib%2FPublicInbox%2FNNTPdeflate.pm;h=10e2337cda97ba1fa83fcecc28fdfd97592c92b3;hp=78da2a588674fe59b48ab1793ab1b2cfbc9dc576;hb=71e8a392d465bf4de60f37ecb3dec5cea5c3a376;hpb=a3c054cbbf2a51be121b3237c5d223acc5c8a2f4 diff --git a/lib/PublicInbox/NNTPdeflate.pm b/lib/PublicInbox/NNTPdeflate.pm index 78da2a58..10e2337c 100644 --- a/lib/PublicInbox/NNTPdeflate.pm +++ b/lib/PublicInbox/NNTPdeflate.pm @@ -30,24 +30,33 @@ my %IN_OPT = ( # global deflate context and buffer my $zbuf = \(my $buf = ''); -my $zout = Compress::Raw::Zlib::Deflate->new( - # nnrpd (INN) and Compress::Raw::Zlib favor MemLevel=9, - # but the zlib C library and git use MemLevel=8 as the default. - # FIXME: sometimes clients fail with 8, so we use 9 - # -MemLevel => 9, - - # needs more testing, nothing obviously different in terms of memory - -Bufsize => 65536, +my $zout; +{ + my $err; + ($zout, $err) = Compress::Raw::Zlib::Deflate->new( + # nnrpd (INN) and Compress::Raw::Zlib favor MemLevel=9, + # the zlib C library and git use MemLevel=8 as the default + # -MemLevel => 9, + -Bufsize => 65536, # same as nnrpd + -WindowBits => -15, # RFC 1951 + -AppendOutput => 1, + ); + $err == Z_OK or die "Failed to initialize zlib deflate stream: $err"; +} - -WindowBits => -15, # RFC 1951 - -AppendOutput => 1, -); sub enable { my ($class, $self) = @_; + my ($in, $err) = Compress::Raw::Zlib::Inflate->new(%IN_OPT); + if ($err != Z_OK) { + $self->err("Inflate->new failed: $err"); + $self->res('403 Unable to activate compression'); + return; + } unlock_hash(%$self); + $self->res('206 Compression active'); bless $self, $class; - $self->{zin} = [ Compress::Raw::Zlib::Inflate->new(%IN_OPT), '' ]; + $self->{zin} = [ $in, '' ]; } # overrides PublicInbox::NNTP::compressed