]> Sergey Matveev's repositories - public-inbox.git/blob - t/git-http-backend.psgi
8cec7d35365b69ac1fd42fedbd585c92df0e39e3
[public-inbox.git] / t / git-http-backend.psgi
1 #!/usr/bin/perl -w
2 # Copyright (C) 2016 all contributors <meta@public-inbox.org>
3 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
4 use strict;
5 use warnings;
6 use PublicInbox::GitHTTPBackend;
7 use PublicInbox::Git;
8 use Plack::Builder;
9 use Plack::Request;
10 use BSD::Resource qw(getrusage);
11 my $git_dir = $ENV{GIANT_GIT_DIR} or die 'GIANT_GIT_DIR not defined in env';
12 my $git = PublicInbox::Git->new($git_dir);
13 builder {
14         enable 'Chunked' if $ENV{TEST_CHUNK};
15         enable 'Head';
16         sub {
17                 my ($env) = @_;
18                 my $pr = Plack::Request->new($env);
19                 if ($pr->path_info =~ m!\A/(.+)\z!s) {
20                         PublicInbox::GitHTTPBackend::serve($pr, $git, $1);
21                 } else {
22                         my $ru = getrusage();
23                         my $b = $ru->maxrss . "\n";
24                         [ 200, [ qw(Content-Type text/plain Content-Length),
25                                  length($b) ], [ $b ] ]
26                 }
27         }
28 }