package PublicInbox::HTTP;
use strict;
use parent qw(PublicInbox::DS);
-use bytes (); # only for bytes::length
use Fcntl qw(:seek);
use Plack::HTTPParser qw(parse_http_request); # XS or pure Perl
use Plack::Util;
return read_input($self) if ref($self->{env});
my $rbuf = $self->{rbuf} // (\(my $x = ''));
- $self->do_read($rbuf, 8192, bytes::length($$rbuf)) or return;
+ $self->do_read($rbuf, 8192, length($$rbuf)) or return;
rbuf_process($self, $rbuf);
}
# (they are rarely-used and git (as of 2.7.2) does not use them)
if ($r == -1 || $env{HTTP_TRAILER} ||
# this length-check is necessary for PURE_PERL=1:
- ($r == -2 && bytes::length($$rbuf) > 0x4000)) {
+ ($r == -2 && length($$rbuf) > 0x4000)) {
return quit($self, 400);
}
if ($r < 0) { # incomplete
# IO::Handle::write returns boolean, this returns bytes written:
sub xwrite ($$$) {
my ($fh, $rbuf, $max) = @_;
- my $w = bytes::length($$rbuf);
+ my $w = length($$rbuf);
$w = $max if $w > $max;
$fh->write($$rbuf, $w) or return;
$w;
sub chunked_write ($$) {
my $self = $_[0];
return if $_[1] eq '';
- msg_more($self, sprintf("%x\r\n", bytes::length($_[1])));
+ msg_more($self, sprintf("%x\r\n", length($_[1])));
msg_more($self, $_[1]);
# use $self->write(\"\n\n") if you care about real-time
$$rbuf =~ s/\A\r\n//s and
return app_dispatch($self, $input, $rbuf);
- return quit($self, 400) if bytes::length($$rbuf) > 2;
+ return quit($self, 400) if length($$rbuf) > 2;
}
if ($len == CHUNK_END) {
if ($$rbuf =~ s/\A\r\n//s) {
$len = CHUNK_START;
- } elsif (bytes::length($$rbuf) > 2) {
+ } elsif (length($$rbuf) > 2) {
return quit($self, 400);
}
}
if (($len + -s $input) > $MAX_REQUEST_BUFFER) {
return quit($self, 413);
}
- } elsif (bytes::length($$rbuf) > CHUNK_MAX_HDR) {
+ } elsif (length($$rbuf) > CHUNK_MAX_HDR) {
return quit($self, 400);
}
# will break from loop since $len >= 0
}
if ($len < 0) { # chunk header is trickled, read more
- $self->do_read($rbuf, 8192, bytes::length($$rbuf)) or
+ $self->do_read($rbuf, 8192, length($$rbuf)) or
return recv_err($self, $len);
# (implicit) goto chunk_start if $r > 0;
}
use strict;
use v5.10.1;
use parent qw(PublicInbox::WwwListing);
-use bytes (); # length
use PublicInbox::Config;
use IO::Compress::Gzip qw(gzip);
use HTTP::Date qw(time2str);
gzip(\$manifest => \(my $out));
[ 200, [ qw(Content-Type application/gzip),
'Last-Modified', time2str($ctx->{-mtime}),
- 'Content-Length', bytes::length($out) ], [ $out ] ]
+ 'Content-Length', length($out) ], [ $out ] ]
}
sub per_inbox {
$gmt = 1;
}
my ($YYYY, $MM, $DD);
- if (bytes::length($date) == 8) { # RFC 3977 allows YYYYMMDD
+ if (length($date) == 8) { # RFC 3977 allows YYYYMMDD
($YYYY, $MM, $DD) = unpack('A4A2A2', $date);
} else { # legacy clients send YYMMDD
my $YY;
# See Documentation/design_www.txt for this.
package PublicInbox::View;
use strict;
-use warnings;
-use bytes (); # only for bytes::length
+use v5.10.1;
use List::Util qw(max);
use PublicInbox::MsgTime qw(msg_datestamp);
use PublicInbox::Hval qw(ascii_html obfuscate_addrs prurl mid_href
return unless $part->{bdy};
my $nl = $idx eq '1' ? '' : "\n"; # like join("\n", ...)
- my $size = bytes::length($part->body);
+ my $size = length($part->body);
# hide attributes normally, unless we want to aid users in
# spotting MUA problems:
package PublicInbox::ViewVCS;
use strict;
-use warnings;
-use bytes (); # only for bytes::length
+use v5.10.1;
use PublicInbox::SolverGit;
use PublicInbox::WwwStream qw(html_oneshot);
use PublicInbox::Linkify;
} elsif (index($$bref, "\0") >= 0) {
[200, [qw(Content-Type application/octet-stream), @cl] ];
} else {
- my $n = bytes::length($$bref);
+ my $n = length($$bref);
if ($n >= $BIN_DETECT || $n == $size) {
return [200, [ 'Content-Type',
'text/plain; charset=UTF-8', @cl ] ];
# - Must not rely on static content
# - UTF-8 is only for user-content, 7-bit US-ASCII for us
package PublicInbox::WWW;
-use 5.010_001;
use strict;
-use warnings;
-use bytes (); # only for bytes::length
+use v5.10.1;
use PublicInbox::Config;
use PublicInbox::Hval;
use URI::Escape qw(uri_unescape);
$css = PublicInbox::UserContent::sample($ctx->{ibx}, $env);
}
defined $css or return r404();
- my $h = [ 'Content-Length', bytes::length($css),
- 'Content-Type', 'text/css' ];
+ my $h = [ 'Content-Length', length($css), 'Content-Type', 'text/css' ];
PublicInbox::GitHTTPBackend::cache_one_year($h);
[ 200, $h, [ $css ] ];
}
my ($ctx, $inbox) = @_;
invalid_inbox($ctx, $inbox) || do {
my $d = $ctx->{ibx}->description . "\n";
- [ 200, [ 'Content-Length', bytes::length($d),
+ utf8::encode($d);
+ [ 200, [ 'Content-Length', length($d),
'Content-Type', 'text/plain' ], [ $d ] ];
};
}
# For retrieving attachments from messages in the WWW interface
package PublicInbox::WwwAttach; # internal package
use strict;
+use v5.10.1;
use parent qw(PublicInbox::GzipFilter);
-use bytes (); # only for bytes::length
use PublicInbox::Eml;
sub referer_match ($) {
$part = "Deep-linking prevented\n";
}
}
- push @{$res->[1]}, 'Content-Length', bytes::length($part);
+ push @{$res->[1]}, 'Content-Length', length($part);
$res->[2]->[0] = $part;
}
package PublicInbox::WwwHighlight;
use strict;
-use warnings;
-use bytes (); # only for bytes::length
+use v5.10.1;
use parent qw(PublicInbox::HlMod);
use PublicInbox::Linkify qw();
use PublicInbox::Hval qw(ascii_html);
$l->linkify_2($$bref);
my $h = [ 'Content-Type', 'text/html; charset=UTF-8' ];
- push @$h, 'Content-Length', bytes::length($$bref);
+ push @$h, 'Content-Length', length($$bref);
[ 200, $h, [ $$bref ] ]
}
# Used by PublicInbox::WWW
package PublicInbox::WwwListing;
use strict;
+use v5.10.1;
use PublicInbox::Hval qw(prurl fmt_ts ascii_html);
use PublicInbox::Linkify;
use PublicInbox::GzipFilter qw(gzf_maybe);
use PublicInbox::ConfigIter;
use PublicInbox::WwwStream;
-use bytes (); # bytes::length
sub ibx_entry {
my ($ctx, $ibx, $ce) = @_;
my $out = $gzf->zflush('</pre><hr><pre>'.
PublicInbox::WwwStream::code_footer($ctx->{env}) .
'</pre></body></html>');
- $h->[3] = bytes::length($out);
+ $h->[3] = length($out);
[ $code, $h, [ $out ] ];
}
# functionality of nginx.
package PublicInbox::WwwStatic;
use strict;
+use v5.10.1;
use parent qw(Exporter);
-use bytes ();
use Fcntl qw(SEEK_SET O_RDONLY O_NONBLOCK);
use POSIX qw(strftime);
use HTTP::Date qw(time2str);
"</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);
+ $h->[3] = length($out);
[ 200, $h, [ $out ] ]
}
# See PublicInbox::GzipFilter parent class for more info.
package PublicInbox::WwwStream;
use strict;
+use v5.10.1;
use parent qw(Exporter PublicInbox::GzipFilter);
our @EXPORT_OK = qw(html_oneshot);
-use bytes (); # length
use PublicInbox::Hval qw(ascii_html prurl ts2str);
our $TOR_URL = 'https://www.torproject.org/';
our $CODE_URL = [ qw(http://7fh6tueqddpjyxjmgtdiueylzoqt6pt7hec3pukyptlmohoowvhde4yd.onion/public-inbox.git
};
$ctx->zmore($$sref) if $sref;
my $bdy = $ctx->zflush(_html_end($ctx));
- $res_hdr->[3] = bytes::length($bdy);
+ $res_hdr->[3] = length($bdy);
[ $code, $res_hdr, [ $bdy ] ]
}
# used for displaying help texts and other non-mail content
package PublicInbox::WwwText;
use strict;
-use warnings;
-use bytes (); # only for bytes::length
+use v5.10.1;
use PublicInbox::Linkify;
use PublicInbox::WwwStream;
use PublicInbox::Hval qw(ascii_html);
$txt = $gzf->translate($txt);
$txt .= $gzf->zflush;
}
- $hdr->[3] = bytes::length($txt);
+ $hdr->[3] = length($txt);
return [ $code, $hdr, [ $txt ] ]
}
use PublicInbox::Eml;
use PublicInbox::Config;
use PublicInbox::Inbox;
-use bytes (); # only for bytes::length
my @mods = qw(DBD::SQLite Search::Xapian HTTP::Request::Common Plack::Test
URI::Escape Plack::Builder);
require_mods(@mods);
+#!perl -w
# Copyright (C) 2017-2021 all contributors <meta@public-inbox.org>
# License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
use strict;
-use warnings;
-use bytes (); # only for bytes::length
+use v5.10.1;
use Test::More;
use PublicInbox::TestCommon;
use PublicInbox::MID qw(mids);
my $mime = PublicInbox::Eml->new(\$_);
$mime->header_set('From' => 'bw@g');
$mime->header_set('To' => 'git@vger.kernel.org');
- my $bytes = bytes::length($mime->as_string);
+ my $bytes = length($mime->as_string);
my $mid = mids($mime->header_obj)->[0];
my $smsg = bless {
bytes => $bytes,
my $tid0 = $dbh->selectrow_array(<<'', undef, $num);
SELECT tid FROM over WHERE num = ? LIMIT 1
- my $bytes = bytes::length($mime->as_string);
+ my $bytes = length($mime->as_string);
my $mid = mids($mime->header_obj)->[0];
my $smsg = bless {
bytes => $bytes,
ok(my $clone = $manifest->{'/alt'}, '/alt in manifest');
is($clone->{owner}, "lorelei \x{100}", 'owner set');
is($clone->{reference}, '/bare', 'reference detected');
- is($clone->{description}, "we're all clones", 'description read');
+ is($clone->{description}, "we're \x{100}ll clones", 'description read');
ok(my $bare = $manifest->{'/bare'}, '/bare in manifest');
is($bare->{description}, 'Unnamed repository',
'missing $GIT_DIR/description fallback');
ok(my $v2epoch1 = $manifest->{'/v2/git/1.git'}, 'v2 epoch 1 appeared');
like($v2epoch1->{description}, qr/ \[epoch 1\]\z/,
'epoch 1 in description');
+
+ $res = $http->get("http://$host:$port/alt/description");
+ is($res->{content}, "we're \xc4\x80ll clones\n", 'UTF-8 description')
+ or diag explain($res);
}
my $td;
is(xsys(@clone, $alt, "$v2/git/$i.git"), 0, "clone epoch $i")
}
ok(open(my $fh, '>', "$v2/inbox.lock"), 'mock a v2 inbox');
- open $fh, '>', "$alt/description" or die;
- print $fh "we're all clones\n" or die;
- close $fh or die;
+ open $fh, '>', "$alt/description" or xbail "open $alt/description $!";
+ print $fh "we're \xc4\x80ll clones\n" or xbail "print $!";
+ close $fh or xbail "write: $alt/description $!";
is(xsys('git', "--git-dir=$alt", qw(config gitweb.owner),
"lorelei \xc4\x80"), 0,
'set gitweb user');
for (qw(v2/git/0.git v2/git/1.git v2/git/2.git)) {
ok(-d "$tmpdir/per-inbox/$_", "grok-pull created $_");
}
+ $td->kill;
+ $td->join;
+ is($?, 0, 'no error in exited process');
+ open $fh, '<', $err or BAIL_OUT("open $err failed: $!");
+ my $eout = do { local $/; <$fh> };
+ unlike($eout, qr/wide/i, 'no Wide character warnings');
+ unlike($eout, qr/uninitialized/i, 'no uninitialized warnings');
}
done_testing();
my $dig = $dig_cls->new;
$dig->add($part);
push @$cmp_arg, "M: ".$dig->hexdigest;
- push @$cmp_arg, "B: ".bytes::length($part);
+ push @$cmp_arg, "B: ".length($part);
} else {
$part =~ s/\s+\z//s;
push @$cmp_arg, "X: ".$part;