]> git.ipfire.org Git - thirdparty/public-inbox.git/commitdiff
www: configurable "-httpbackend" named limiter
authorEric Wong <e@80x24.org>
Tue, 28 Jan 2025 08:31:12 +0000 (08:31 +0000)
committerEric Wong <e@80x24.org>
Tue, 4 Feb 2025 09:06:17 +0000 (09:06 +0000)
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.

Documentation/public-inbox-config.pod
lib/PublicInbox/Cgit.pm
lib/PublicInbox/GitHTTPBackend.pm
lib/PublicInbox/WWW.pm
lib/PublicInbox/WwwCoderepo.pm

index 6c4d633a69b59ee266e94b821a77bc5b3c1bd2f5..6f8ec1f30047e065333dda69e54db99ff87230b6 100644 (file)
@@ -561,8 +561,11 @@ C<RLIMIT_*> keys may be set to enforce resource limits for
 a particular limiter (L<BSD::Resource(3pm)> is required).
 
 Default named-limiters are prefixed with "-".  Currently,
-the "-cgit" named limiter is reserved for instances spawning
-cgit via C<publicinbox.cgitrc>
+the C<-cgit> named limiter is reserved for instances spawning
+cgit via C<publicinbox.cgitrc>.  The C<-httpbackend> named
+limiter (in public-inbox 2.0+) governs all L<git-http-backend(1)>
+processes for inboxes and coderepos for a given public-inbox
+config file.
 
 =over 8
 
index 78fc9ca034ef351d584d2e7aa9d293049fb4e520..480d1df691280c4722483581f1eb6b58a81af941 100644 (file)
@@ -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})) {
index ac610d4b130902d3ad9e8089666c8b5a2eecf127..5dc07143931d9fecddfe4b981e3d233fe3045a38 100644 (file)
@@ -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);
index 420132d9e8818ecc709ce2901d7a9f226fd6b3c2..05ec241629a6b19e7f95ecb9079df38dd0cfc9d9 100644 (file)
@@ -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 {
index 8be8ada01e66a6095674c26ef2f67306e46147ba..fa3c4acf5876a2964b2907b3b264cd127b52206d 100644 (file)
@@ -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;