]> Sergey Matveev's repositories - public-inbox.git/blob - t/git-http-backend.psgi
http: chunk in the server, not middleware
[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 'Head';
15         sub {
16                 my ($env) = @_;
17                 my $pr = Plack::Request->new($env);
18                 if ($pr->path_info =~ m!\A/(.+)\z!s) {
19                         PublicInbox::GitHTTPBackend::serve($pr, $git, $1);
20                 } else {
21                         my $ru = getrusage();
22                         my $b = $ru->maxrss . "\n";
23                         [ 200, [ qw(Content-Type text/plain Content-Length),
24                                  length($b) ], [ $b ] ]
25                 }
26         }
27 }