CHUNK_END => -2, # \r\n
CHUNK_TLR_END => -3, # (trailers*)?\r\n
CHUNK_MAX_HDR => 256,
+ IO_SIZE => 1 << 16,
};
sub new {
\n)* \r\n)//ismx) {
return pass_trailers $self, $1;
}
- die 'chunk not terminated' if length($$rbuf) > 0x4000;
+ die 'chunk not terminated' if length($$rbuf) > IO_SIZE;
}
if ($len == CHUNK_END) {
if ($$rbuf =~ s/\A\r\n//s) {
} # else break from loop since $len >= 0
}
if ($len < 0) {
- pass_refill($self, 0x4000, \&pass_res_chunked, $len) or
+ pass_refill($self, IO_SIZE, \&pass_res_chunked, $len) or
return;
# (implicit) goto chunk_start if $r > 0;
}
}
if ($$rbuf eq '') {
# read more of current chunk
- pass_refill($self, 0x4000,
+ pass_refill($self, IO_SIZE,
\&pass_res_chunked, $len) or return;
}
}
$len = _pass_res_block($self, $len) // return;
}
if ($$rbuf eq '' && $len) {
- my $n = $len > 0x4000 ? 0x4000 : $len;
+ my $n = $len > IO_SIZE ? IO_SIZE : $len;
pass_refill($self, $n, \&pass_res_identity, $len) or
return;
}
$$rbuf = '';
}
if ($$rbuf eq '') {
- my $r = pass_refill($self, 0x4000,
+ my $r = pass_refill($self, IO_SIZE,
\&pass_res_until_eof, undef) // return;
last if $r == 0; # done
}
my ($self) = @_;
my ($rbuf, $r, $code, $phdr);
$rbuf = $self->{rbuf} // do {
- $self->do_read(\(my $buf = ''), 0x4000) or
+ $self->do_read(\(my $buf = ''), IO_SIZE) or
return read_err $self, \&pass_res_hdr;
$self->{rbuf} = \$buf;
};
if ($r == -2) { # incomplete
length($$rbuf) > 0x4000 and
die 'upstream response headers too large';
- $self->do_read($rbuf, 8192, length($$rbuf)) or return
+ $self->do_read($rbuf, IO_SIZE, length($$rbuf)) or return
read_err $self, \&pass_res_hdr;
} else {
die "upstream sent bad response headers (r=$r)";
# n.b. PublicInbox::HTTP always reads the entire request body
# before dispatching the PSGI app
my $r = $self->{req_left};
- $r = 0x4000 if $r > 0x4000;
+ $r = IO_SIZE if $r > IO_SIZE;
$r = $self->{env}->{'psgi.input'}->read(my $buf, $r) //
die "input->read: $! ($self->{req_left} bytes left)";
die "input->read: EOF ($self->{req_left} bytes left)" if $r == 0;