about summary refs log tree commit homepage
path: root/lib
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2016-05-30 00:51:44 +0000
committerEric Wong <e@80x24.org>2016-05-30 00:55:36 +0000
commit21cf3d6a9a4be06deca4adea9de071f772fb1c57 (patch)
treed0bd52cc06d0bdca64f5c03d25b24e31d29d50d3 /lib
parent9665b1ffe0c5417e54ccd313794577d7c62c429c (diff)
downloadpublic-inbox-21cf3d6a9a4be06deca4adea9de071f772fb1c57.tar.gz
Plack::Request is unnecessary overhead for this given the
strictness of git-http-backend.  Furthermore, having to make
commit 311c2adc8c63 ("avoid Plack::Request parsing body")
to avoid tempfiles should not have been necessary.
Diffstat (limited to 'lib')
-rw-r--r--lib/PublicInbox/GitHTTPBackend.pm26
-rw-r--r--lib/PublicInbox/WWW.pm8
2 files changed, 17 insertions, 17 deletions
diff --git a/lib/PublicInbox/GitHTTPBackend.pm b/lib/PublicInbox/GitHTTPBackend.pm
index 58e75cde..9660d21e 100644
--- a/lib/PublicInbox/GitHTTPBackend.pm
+++ b/lib/PublicInbox/GitHTTPBackend.pm
@@ -40,15 +40,17 @@ sub r ($;$) {
 }
 
 sub serve {
-        my ($cgi, $git, $path) = @_;
+        my ($env, $git, $path) = @_;
 
-        my $service = $cgi->query_parameters->get('service') || '';
-        if ($service =~ /\Agit-\w+-pack\z/ || $path =~ /\Agit-\w+-pack\z/) {
-                my $ok = serve_smart($cgi, $git, $path);
+        # Documentation/technical/http-protocol.txt in git.git
+        # requires one and exactly one query parameter:
+        if ($env->{QUERY_STRING} =~ /\Aservice=git-\w+-pack\z/ ||
+                                $path =~ /\Agit-\w+-pack\z/) {
+                my $ok = serve_smart($env, $git, $path);
                 return $ok if $ok;
         }
 
-        serve_dumb($cgi, $git, $path);
+        serve_dumb($env, $git, $path);
 }
 
 sub err ($@) {
@@ -63,7 +65,7 @@ sub drop_client ($) {
 }
 
 sub serve_dumb {
-        my ($cgi, $git, $path) = @_;
+        my ($env, $git, $path) = @_;
 
         my @h;
         my $type;
@@ -82,7 +84,6 @@ sub serve_dumb {
         return r(404) unless -f $f && -r _; # just in case it's a FIFO :P
         my @st = stat(_);
         my $size = $st[7];
-        my $env = $cgi->{env};
 
         # TODO: If-Modified-Since and Last-Modified?
         open my $in, '<', $f or return r(404);
@@ -90,7 +91,7 @@ sub serve_dumb {
         my $code = 200;
         push @h, 'Content-Type', $type;
         if (($env->{HTTP_RANGE} || '') =~ /\bbytes=(\d*)-(\d*)\z/) {
-                ($code, $len) = prepare_range($cgi, $in, \@h, $1, $2, $size);
+                ($code, $len) = prepare_range($env, $in, \@h, $1, $2, $size);
                 if ($code == 416) {
                         push @h, 'Content-Range', "bytes */$size";
                         return [ 416, \@h, [] ];
@@ -118,7 +119,7 @@ sub serve_dumb {
 }
 
 sub prepare_range {
-        my ($cgi, $in, $h, $beg, $end, $size) = @_;
+        my ($env, $in, $h, $beg, $end, $size) = @_;
         my $code = 200;
         my $len = $size;
         if ($beg eq '') {
@@ -152,7 +153,7 @@ sub prepare_range {
                         push @$h, "bytes $beg-$end/$size";
 
                         # FIXME: Plack::Middleware::Deflater bug?
-                        $cgi->{env}->{'psgix.no-compress'} = 1;
+                        $env->{'psgix.no-compress'} = 1;
                 }
         }
         ($code, $len);
@@ -160,8 +161,7 @@ sub prepare_range {
 
 # returns undef if 403 so it falls back to dumb HTTP
 sub serve_smart {
-        my ($cgi, $git, $path) = @_;
-        my $env = $cgi->{env};
+        my ($env, $git, $path) = @_;
         my $in = $env->{'psgi.input'};
         my $fd = eval { fileno($in) };
         unless (defined $fd && $fd >= 0) {
@@ -201,7 +201,7 @@ sub serve_smart {
                 return if !defined($r) && ($!{EINTR} || $!{EAGAIN});
                 return r(500, 'http-backend error') unless $r;
                 $r = parse_cgi_headers(\$buf) or return; # incomplete headers
-                $r->[0] == 403 ? serve_dumb($cgi, $git, $path) : $r;
+                $r->[0] == 403 ? serve_dumb($env, $git, $path) : $r;
         };
         my $res;
         my $async = $env->{'pi-httpd.async'};
diff --git a/lib/PublicInbox/WWW.pm b/lib/PublicInbox/WWW.pm
index cf370afa..88d4f6f0 100644
--- a/lib/PublicInbox/WWW.pm
+++ b/lib/PublicInbox/WWW.pm
@@ -48,7 +48,7 @@ sub call {
                  $path_info =~ m!$INBOX_RE/(git-upload-pack)\z!) {
                 my $path = $2;
                 return (invalid_inbox($self, $ctx, $1) ||
-                        serve_git($cgi, $ctx->{git}, $path));
+                        serve_git($env, $ctx->{git}, $path));
         }
         elsif ($method !~ /\AGET|HEAD\z/) {
                 return r(405, 'Method Not Allowed');
@@ -68,7 +68,7 @@ sub call {
                                 ($PublicInbox::GitHTTPBackend::ANY)\z!ox) {
                 my $path = $2;
                 invalid_inbox($self, $ctx, $1) ||
-                        serve_git($cgi, $ctx->{git}, $path);
+                        serve_git($env, $ctx->{git}, $path);
         } elsif ($path_info =~ m!$INBOX_RE/([\w-]+).mbox\.gz\z!o) {
                 serve_mbox_range($self, $ctx, $1, $2);
         } elsif ($path_info =~ m!$INBOX_RE/$MID_RE/$END_RE\z!o) {
@@ -424,8 +424,8 @@ sub msg_page {
 }
 
 sub serve_git {
-        my ($cgi, $git, $path) = @_;
-        PublicInbox::GitHTTPBackend::serve($cgi, $git, $path);
+        my ($env, $git, $path) = @_;
+        PublicInbox::GitHTTPBackend::serve($env, $git, $path);
 }
 
 sub serve_mbox_range {