summary |
shortlog |
log |
commit | commitdiff |
tree
raw |
patch |
inline | side by side (from parent 1:
8968889)
This allows multiple instances the WWW app from
running within the same process space
use Plack::Request;
use Plack::Builder;
my $have_deflater = eval { require Plack::Middleware::Deflater; 1 };
use Plack::Request;
use Plack::Builder;
my $have_deflater = eval { require Plack::Middleware::Deflater; 1 };
+my $www = PublicInbox::WWW->new;
builder {
enable 'Chunked';
if ($have_deflater) {
builder {
enable 'Chunked';
if ($have_deflater) {
# See Plack::Middleware::ReverseProxy documentation for details
# enable 'ReverseProxy';
enable 'Head';
# See Plack::Middleware::ReverseProxy documentation for details
# enable 'ReverseProxy';
enable 'Head';
- sub {
- my $req = Plack::Request->new(@_);
- PublicInbox::WWW::run($req, $req->method);
- }
+ sub { $www->call(@_) };
our $LISTNAME_RE = qr!\A/([\w\.\-]+)!;
our $MID_RE = qr!([^/]+)!;
our $END_RE = qr!(f/|T/|t/|R/|t\.mbox(?:\.gz)?|t\.atom|raw|)!;
our $LISTNAME_RE = qr!\A/([\w\.\-]+)!;
our $MID_RE = qr!([^/]+)!;
our $END_RE = qr!(f/|T/|t/|R/|t\.mbox(?:\.gz)?|t\.atom|raw|)!;
-sub run {
- my ($cgi, $method) = @_;
+sub new {
+ my ($class, $pi_config) = @_;
$pi_config ||= PublicInbox::Config->new;
$pi_config ||= PublicInbox::Config->new;
- my $ctx = { cgi => $cgi, pi_config => $pi_config };
+ bless { pi_config => $pi_config }, $class;
+}
+
+# backwards compatibility, do not use
+sub run {
+ my ($req, $method) = @_;
+ PublicInbox::WWW->new->call($req->env);
+}
+
+sub call {
+ my ($self, $env) = @_;
+ my $cgi = Plack::Request->new($env);
+ my $ctx = { cgi => $cgi, pi_config => $self->{pi_config} };
my $path_info = $cgi->path_info;
my $path_info = $cgi->path_info;
+ my $method = $cgi->method;
if ($method eq 'POST' &&
$path_info =~ m!$LISTNAME_RE/(git-upload-pack)\z!) {
my $path = $2;
if ($method eq 'POST' &&
$path_info =~ m!$LISTNAME_RE/(git-upload-pack)\z!) {
my $path = $2;
# returns undef if valid, array ref response if invalid
sub invalid_list {
my ($ctx, $listname) = @_;
# returns undef if valid, array ref response if invalid
sub invalid_list {
my ($ctx, $listname) = @_;
- my $git_dir = $pi_config->get($listname, "mainrepo");
+ my $git_dir = $ctx->{pi_config}->get($listname, "mainrepo");
if (defined $git_dir) {
$ctx->{git_dir} = $git_dir;
$ctx->{git} = PublicInbox::Git->new($git_dir);
if (defined $git_dir) {
$ctx->{git_dir} = $git_dir;
$ctx->{git} = PublicInbox::Git->new($git_dir);
join("\n", map { "\t$_" } @urls);
}
join("\n", map { "\t$_" } @urls);
}
- my $addr = $pi_config->get($listname, 'address');
+ my $addr = $ctx->{pi_config}->get($listname, 'address');
if (ref($addr) eq 'ARRAY') {
$addr = $addr->[0]; # first address is primary
}
if (ref($addr) eq 'ARRAY') {
$addr = $addr->[0]; # first address is primary
}
"$0 runs in /, command-line paths must be absolute\n";
}
} else {
"$0 runs in /, command-line paths must be absolute\n";
}
} else {
+ my $www = PublicInbox::WWW->new;
$app = eval {
my $deflate_types = eval {
require Plack::Middleware::Deflater;
$app = eval {
my $deflate_types = eval {
require Plack::Middleware::Deflater;
content_type => $deflate_types
}
enable 'Head';
content_type => $deflate_types
}
enable 'Head';
- sub {
- my $req = Plack::Request->new(@_);
- PublicInbox::WWW::run($req,
- $req->method);
- };
+ sub { $www->call(@_) };
use Plack::Handler::CGI;
use PublicInbox::WWW;
BEGIN { PublicInbox::WWW->preload if $ENV{MOD_PERL} }
use Plack::Handler::CGI;
use PublicInbox::WWW;
BEGIN { PublicInbox::WWW->preload if $ENV{MOD_PERL} }
+my $www = PublicInbox::WWW->new;
my $have_deflater = eval { require Plack::Middleware::Deflater; 1 };
my $app = builder {
if ($have_deflater) {
my $have_deflater = eval { require Plack::Middleware::Deflater; 1 };
my $app = builder {
if ($have_deflater) {
# enable 'ReverseProxy';
enable 'Head';
# enable 'ReverseProxy';
enable 'Head';
- sub {
- my $req = Plack::Request->new(@_);
- PublicInbox::WWW::run($req, $req->method);
- }
+ sub { $www->call(@_) };
};
Plack::Handler::CGI->new->run($app);
};
Plack::Handler::CGI->new->run($app);