]> Sergey Matveev's repositories - public-inbox.git/commitdiff
wwwstream: oneshot sets content-length
authorEric Wong <e@yhbt.net>
Sat, 21 Mar 2020 02:03:48 +0000 (02:03 +0000)
committerEric Wong <e@yhbt.net>
Wed, 25 Mar 2020 01:48:35 +0000 (01:48 +0000)
PublicInbox::HTTP will chunk, otherwise, and that's
extra overhead which isn't needed.

lib/PublicInbox/WwwStream.pm

index fceef745d0c4ec2291448a2ff131a68880030530..985e02622048b4a2ada72510aa84d4ab6273d7be 100644 (file)
@@ -9,6 +9,7 @@
 package PublicInbox::WwwStream;
 use strict;
 use warnings;
 package PublicInbox::WwwStream;
 use strict;
 use warnings;
+use bytes (); # length
 use PublicInbox::Hval qw(ascii_html prurl);
 our $TOR_URL = 'https://www.torproject.org/';
 our $CODE_URL = 'https://public-inbox.org/public-inbox.git';
 use PublicInbox::Hval qw(ascii_html prurl);
 our $TOR_URL = 'https://www.torproject.org/';
 our $CODE_URL = 'https://public-inbox.org/public-inbox.git';
@@ -170,14 +171,18 @@ sub getline {
 }
 
 sub oneshot {
 }
 
 sub oneshot {
-       my ($ctx, $code, $strref) = @_;
+       my ($ctx, $code, $sref) = @_;
        my $self = bless {
                ctx => $ctx,
                base_url => base_url($ctx),
        }, __PACKAGE__;
        my $self = bless {
                ctx => $ctx,
                base_url => base_url($ctx),
        }, __PACKAGE__;
-       [ $code, [ 'Content-Type', 'text/html; charset=UTF-8' ], [
-               _html_top($self), $strref ? $$strref : (), _html_end($self)
-       ] ]
+       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 ];
 }
 
 1;
 }
 
 1;