From: Eric Wong Date: Tue, 28 Jan 2025 08:31:12 +0000 (+0000) Subject: www: configurable "-httpbackend" named limiter X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=eb40d1e62ed687e31785da0cebe38cba9f8492cc;p=thirdparty%2Fpublic-inbox.git www: configurable "-httpbackend" named limiter The default limiter being hard-coded to 32 is excessive for smaller systems. With dozens or hundreds of inboxes, configuring all inboxes to point to a user-defined limiter is tedious, as well. So give WWW admins the opportunity to configure the limiter for all git-http-backend(1) processes with one `publicinbox.-httpbackend.max' knob. --- diff --git a/Documentation/public-inbox-config.pod b/Documentation/public-inbox-config.pod index 6c4d633a6..6f8ec1f30 100644 --- a/Documentation/public-inbox-config.pod +++ b/Documentation/public-inbox-config.pod @@ -561,8 +561,11 @@ C keys may be set to enforce resource limits for a particular limiter (L is required). Default named-limiters are prefixed with "-". Currently, -the "-cgit" named limiter is reserved for instances spawning -cgit via C +the C<-cgit> named limiter is reserved for instances spawning +cgit via C. The C<-httpbackend> named +limiter (in public-inbox 2.0+) governs all L +processes for inboxes and coderepos for a given public-inbox +config file. =over 8 diff --git a/lib/PublicInbox/Cgit.pm b/lib/PublicInbox/Cgit.pm index 78fc9ca03..480d1df69 100644 --- a/lib/PublicInbox/Cgit.pm +++ b/lib/PublicInbox/Cgit.pm @@ -93,7 +93,7 @@ sub call { if ($path_info =~ m!\A/(.+?)/($PublicInbox::GitHTTPBackend::ANY)\z!ox) { my ($nick, $path) = ($1, $2); if (my $git = $self->{pi_cfg}->get_coderepo($nick)) { - return serve($env, $git, $path); + return serve($env, $git, $path, $self->{pi_cfg}); } } elsif ($path_info =~ m!$self->{static}! && defined($cgit_data = $self->{cgit_data})) { diff --git a/lib/PublicInbox/GitHTTPBackend.pm b/lib/PublicInbox/GitHTTPBackend.pm index ac610d4b1..5dc071439 100644 --- a/lib/PublicInbox/GitHTTPBackend.pm +++ b/lib/PublicInbox/GitHTTPBackend.pm @@ -31,13 +31,13 @@ our $ANY = join('|', @binary, @text, 'git-upload-pack'); my $TEXT = join('|', @text); sub serve { - my ($env, $git, $path) = @_; + my ($env, $git, $path, $pi_cfg) = @_; # Documentation/technical/http-protocol.txt in git.git # requires one and exactly one query parameter: if ($env->{QUERY_STRING} =~ /\Aservice=git-[A-Za-z0-9_]+-pack\z/ || $path =~ /\Agit-[A-Za-z0-9_]+-pack\z/) { - my $ok = serve_smart($env, $git, $path); + my $ok = serve_smart($env, $git, $path, $pi_cfg); return $ok if $ok; } @@ -86,8 +86,8 @@ sub ghb_parse_hdr { # header parser for Qspawn } # returns undef if 403 so it falls back to dumb HTTP -sub serve_smart { - my ($env, $git, $path) = @_; +sub serve_smart ($$$;$) { + my ($env, $git, $path, $pi_cfg) = @_; my %env = %ENV; # GIT_COMMITTER_NAME, GIT_COMMITTER_EMAIL # may be set in the server-process and are passed as-is @@ -101,7 +101,9 @@ sub serve_smart { my $val = $env->{$name}; $env{$name} = $val if defined $val; } - my $limiter = $git->{-httpbackend_limiter} || $default_limiter; + my $limiter = $git->{-httpbackend_limiter} // + ($pi_cfg ? $pi_cfg->limiter('-httpbackend') : undef) // + $default_limiter; $env{GIT_HTTP_EXPORT_ALL} = '1'; $env{PATH_TRANSLATED} = "$git->{git_dir}/$path"; my $rdr = input_prepare($env) or return r(500); diff --git a/lib/PublicInbox/WWW.pm b/lib/PublicInbox/WWW.pm index 420132d9e..05ec24162 100644 --- a/lib/PublicInbox/WWW.pm +++ b/lib/PublicInbox/WWW.pm @@ -487,10 +487,10 @@ sub msg_page { sub serve_git { my ($ctx, $epoch, $path) = @_; - my $env = $ctx->{env}; my $ibx = $ctx->{ibx}; my $git = defined $epoch ? $ibx->git_epoch($epoch) : $ibx->git; - $git ? PublicInbox::GitHTTPBackend::serve($env, $git, $path) : r404(); + $git ? PublicInbox::GitHTTPBackend::serve($ctx->{env}, + $git, $path, $ctx->{www}->{pi_cfg}) : r404(); } sub mbox_results { diff --git a/lib/PublicInbox/WwwCoderepo.pm b/lib/PublicInbox/WwwCoderepo.pm index 8be8ada01..fa3c4acf5 100644 --- a/lib/PublicInbox/WwwCoderepo.pm +++ b/lib/PublicInbox/WwwCoderepo.pm @@ -335,7 +335,8 @@ sub srv { # endpoint called by PublicInbox::WWW my $pi_cfg = $self->{pi_cfg}; if ($path_info =~ m!\A/(.+?)/($PublicInbox::GitHTTPBackend::ANY)\z!x and ($git = $pi_cfg->get_coderepo($1))) { - PublicInbox::GitHTTPBackend::serve($ctx->{env},$git,$2); + PublicInbox::GitHTTPBackend::serve($ctx->{env}, + $git, $2, $pi_cfg); } elsif ($path_info =~ m!\A/(.+?)/\z! and ($ctx->{git} = $pi_cfg->get_coderepo($1))) { $ctx->{wcr} = $self;