From 15e14f11af0b9919f11e0c186b365ae0154e7e77 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Thu, 22 Dec 2016 07:29:17 +0000 Subject: doc: various comments on async handling Notes for future developers (myself included) since we can't assume people can read my mind. --- lib/PublicInbox/GitHTTPBackend.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/PublicInbox/GitHTTPBackend.pm') diff --git a/lib/PublicInbox/GitHTTPBackend.pm b/lib/PublicInbox/GitHTTPBackend.pm index 1987a013..a069fd94 100644 --- a/lib/PublicInbox/GitHTTPBackend.pm +++ b/lib/PublicInbox/GitHTTPBackend.pm @@ -227,7 +227,7 @@ sub serve_smart { $r->[0] == 403 ? serve_dumb($env, $git, $path) : $r; }; my $res; - my $async = $env->{'pi-httpd.async'}; + my $async = $env->{'pi-httpd.async'}; # XXX unstable API my $io = $env->{'psgix.io'}; my $cb = sub { my $r = $rd_hdr->() or return; -- cgit v1.2.3-24-ge0c7 From 1aff1f07b5f6acc661aefc0d6fc1d744e6f8025d Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Sun, 25 Dec 2016 06:39:13 +0000 Subject: githttpbackend: minor readability improvement Use a more meaningful variable name for the Qspawn object, since this module is the reference for its use. --- lib/PublicInbox/GitHTTPBackend.pm | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'lib/PublicInbox/GitHTTPBackend.pm') diff --git a/lib/PublicInbox/GitHTTPBackend.pm b/lib/PublicInbox/GitHTTPBackend.pm index a069fd94..86b8ebcc 100644 --- a/lib/PublicInbox/GitHTTPBackend.pm +++ b/lib/PublicInbox/GitHTTPBackend.pm @@ -206,11 +206,11 @@ sub serve_smart { } $env{GIT_HTTP_EXPORT_ALL} = '1'; $env{PATH_TRANSLATED} = "$git_dir/$path"; - my %rdr = ( 0 => fileno($in) ); - my $x = PublicInbox::Qspawn->new([qw(git http-backend)], \%env, \%rdr); + my $rdr = { 0 => fileno($in) }; + my $qsp = PublicInbox::Qspawn->new([qw(git http-backend)], \%env, $rdr); my ($fh, $rpipe); my $end = sub { - if (my $err = $x->finish) { + if (my $err = $qsp->finish) { err($env, "git http-backend ($git_dir): $err"); } $fh->close if $fh; # async-only @@ -258,7 +258,7 @@ sub serve_smart { # holding the input here is a waste of FDs and memory $env->{'psgi.input'} = undef; - $x->start($limiter, sub { # may run later, much later... + $qsp->start($limiter, sub { # may run later, much later... ($rpipe) = @_; $in = undef; if ($async) { -- cgit v1.2.3-24-ge0c7 From 292ca34140489da2c3458e1d45da5a9ae4af540d Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Sun, 25 Dec 2016 06:52:03 +0000 Subject: githttpbackend: simplify compatibility code Fewer conditionals means theres fewer code paths to test and makes things easier-to-read. --- lib/PublicInbox/GitHTTPBackend.pm | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) (limited to 'lib/PublicInbox/GitHTTPBackend.pm') diff --git a/lib/PublicInbox/GitHTTPBackend.pm b/lib/PublicInbox/GitHTTPBackend.pm index 86b8ebcc..4ad3fd1e 100644 --- a/lib/PublicInbox/GitHTTPBackend.pm +++ b/lib/PublicInbox/GitHTTPBackend.pm @@ -46,6 +46,9 @@ sub r ($;$) { sub serve { my ($env, $git, $path) = @_; + # XXX compatibility... ugh, can we stop supporting this? + $git = PublicInbox::Git->new($git) unless ref($git); + # Documentation/technical/http-protocol.txt in git.git # requires one and exactly one query parameter: if ($env->{QUERY_STRING} =~ /\Aservice=git-\w+-pack\z/ || @@ -98,7 +101,7 @@ sub serve_dumb { return r(404); } - my $f = (ref $git ? $git->{git_dir} : $git) . '/' . $path; + my $f = $git->{git_dir} . '/' . $path; return r(404) unless -f $f && -r _; # just in case it's a FIFO :P my $size = -s _; @@ -196,14 +199,8 @@ sub serve_smart { my $val = $env->{$name}; $env{$name} = $val if defined $val; } - my ($git_dir, $limiter); - if (ref $git) { - $limiter = $git->{-httpbackend_limiter} || $default_limiter; - $git_dir = $git->{git_dir}; - } else { - $limiter = $default_limiter; - $git_dir = $git; - } + my $limiter = $git->{-httpbackend_limiter} || $default_limiter; + my $git_dir = $git->{git_dir}; $env{GIT_HTTP_EXPORT_ALL} = '1'; $env{PATH_TRANSLATED} = "$git_dir/$path"; my $rdr = { 0 => fileno($in) }; -- cgit v1.2.3-24-ge0c7 From f773704937f088c2ef6d5be1038e541284cf5372 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Sun, 25 Dec 2016 07:33:02 +0000 Subject: githttpbackend: minor cleanups to improve readability Fewer returns improves readability and the diffstat agrees. --- lib/PublicInbox/GitHTTPBackend.pm | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) (limited to 'lib/PublicInbox/GitHTTPBackend.pm') diff --git a/lib/PublicInbox/GitHTTPBackend.pm b/lib/PublicInbox/GitHTTPBackend.pm index 4ad3fd1e..1fa5e30e 100644 --- a/lib/PublicInbox/GitHTTPBackend.pm +++ b/lib/PublicInbox/GitHTTPBackend.pm @@ -225,7 +225,6 @@ sub serve_smart { }; my $res; my $async = $env->{'pi-httpd.async'}; # XXX unstable API - my $io = $env->{'psgix.io'}; my $cb = sub { my $r = $rd_hdr->() or return; $rd_hdr = undef; @@ -236,17 +235,16 @@ sub serve_smart { $rpipe->close; $end->(); } - return $res->($r); - } - if ($async) { + $res->($r); + } elsif ($async) { $fh = $res->($r); - return $async->async_pass($io, $fh, \$buf); + $async->async_pass($env->{'psgix.io'}, $fh, \$buf); + } else { # for synchronous PSGI servers + require PublicInbox::GetlineBody; + $r->[2] = PublicInbox::GetlineBody->new($rpipe, $end, + $buf); + $res->($r); } - - # for synchronous PSGI servers - require PublicInbox::GetlineBody; - $r->[2] = PublicInbox::GetlineBody->new($rpipe, $end, $buf); - $res->($r); }; sub { ($res) = @_; -- cgit v1.2.3-24-ge0c7