use PublicInbox::DS qw(msg_more);
use PublicInbox::Syscall qw(EPOLLIN EPOLLONESHOT);
use PublicInbox::Tmpfile;
use PublicInbox::DS qw(msg_more);
use PublicInbox::Syscall qw(EPOLLIN EPOLLONESHOT);
use PublicInbox::Tmpfile;
# Use the same configuration parameter as git since this is primarily
# a slow-client sponge for git-http-backend
# TODO: support per-respository http.maxRequestBuffer somehow...
# Use the same configuration parameter as git since this is primarily
# a slow-client sponge for git-http-backend
# TODO: support per-respository http.maxRequestBuffer somehow...
# otherwise we can be buffering infinitely w/o backpressure
return read_input($self) if ref($self->{env});
# otherwise we can be buffering infinitely w/o backpressure
return read_input($self) if ref($self->{env});
- my $rbuf = $self->{rbuf} // (\(my $x = ''));
- $self->do_read($rbuf, 8192, length($$rbuf)) or return;
- rbuf_process($self, $rbuf);
-}
-
-sub rbuf_process {
- my ($self, $rbuf) = @_;
- $rbuf //= $self->{rbuf} // (\(my $x = ''));
- my $r = parse_http_request($$rbuf, \%env);
-
- # We do not support Trailers in chunked requests, for now
- # (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 && length($$rbuf) > 0x4000)) {
- return quit($self, 400);
- }
- if ($r < 0) { # incomplete
- $self->rbuf_idle($rbuf);
- return $self->requeue;
+ my $r;
+ while (($r = parse_http_request($$rbuf, \%env)) < 0) {
+ # We do not support Trailers in chunked requests, for
+ # now (they are rarely-used and git (as of 2.7.2) does
+ # not use them).
+ # this length-check is necessary for PURE_PERL=1:
+ if ($r == -1 || $env{HTTP_TRAILER} ||
+ ($r == -2 && length($$rbuf) > 0x4000)) {
+ return quit($self, 400);
+ }
+ $self->do_read($rbuf, 8192, length($$rbuf)) or return;
- my $len = input_prepare($self, \%env);
- defined $len or return write_err($self, undef); # EMFILE/ENFILE
+ my $len = input_prepare($self, \%env) //
+ return write_err($self, undef); # EMFILE/ENFILE
$len ? read_input($self, $rbuf) : app_dispatch($self, undef, $rbuf);
}
$len ? read_input($self, $rbuf) : app_dispatch($self, undef, $rbuf);
}
-# IO::Handle::write returns boolean, this returns bytes written:
-sub xwrite ($$$) {
- my ($fh, $rbuf, $max) = @_;
- my $w = length($$rbuf);
- $w = $max if $w > $max;
- $fh->write($$rbuf, $w) or return;
- $w;
-}
-
return write_err($self, $len) unless $w;
$len -= $w;
die "BUG: $len < 0 (w=$w)" if $len < 0;
return write_err($self, $len) unless $w;
$len -= $w;
die "BUG: $len < 0 (w=$w)" if $len < 0;
-sub next_request ($) {
- my ($self) = @_;
- if ($self->{rbuf}) {
- # avoid recursion for pipelined requests
- PublicInbox::DS::requeue(\&process_pipelineq) if !@$pipelineq;
- push @$pipelineq, $self;
- } else { # wait for next request
- $self->requeue;
- }
-}
-
} else {
$len = $env->{CONTENT_LENGTH};
if (defined $len) {
# rfc7230 3.3.3.4
return quit($self, 400) if $len !~ /\A[0-9]+\z/;
} else {
$len = $env->{CONTENT_LENGTH};
if (defined $len) {
# rfc7230 3.3.3.4
return quit($self, 400) if $len !~ /\A[0-9]+\z/;
$self->{env} = $env;
$self->{input_left} = $len || 0;
}
sub env_chunked { ($_[0]->{HTTP_TRANSFER_ENCODING} // '') =~ /\Achunked\z/i }
$self->{env} = $env;
$self->{input_left} = $len || 0;
}
sub env_chunked { ($_[0]->{HTTP_TRANSFER_ENCODING} // '') =~ /\Achunked\z/i }