- my $self = bless {
- ctx => $ctx,
- base_url => base_url($ctx),
- }, __PACKAGE__;
- my @x = (_html_top($self), $sref ? $$sref : (), _html_end($self));
- my $len = 0;
- $len += bytes::length($_) for @x;
- [ $code, [
- 'Content-Type' => 'text/html; charset=UTF-8',
- 'Content-Length' => $len
- ], \@x ];
+ $ctx->{base_url} = base_url($ctx);
+ bless $ctx, __PACKAGE__;
+ my @x;
+ my $h = [ 'Content-Type' => 'text/html; charset=UTF-8',
+ 'Content-Length' => undef ];
+ if (my $gzf = gzf_maybe($h, $ctx->{env})) {
+ $gzf->zmore(html_top($ctx));
+ $gzf->zmore($$sref) if $sref;
+ $x[0] = $gzf->zflush(_html_end($ctx));
+ $h->[3] = length($x[0]);
+ } else {
+ @x = (html_top($ctx), $sref ? $$sref : (), _html_end($ctx));
+ $h->[3] += bytes::length($_) for @x;
+ }
+ [ $code, $h, \@x ]