unofficial mirror of meta@public-inbox.org
 help / color / mirror / Atom feed
* [PATCH] config: fix NewsWWW fallback for newsgroups in HTTP URLs
@ 2016-05-27  9:06 Eric Wong
  0 siblings, 0 replies; only message in thread
From: Eric Wong @ 2016-05-27  9:06 UTC (permalink / raw)
  To: meta

Oops, added a test to prevent regressions while we're at it.
---
 lib/PublicInbox/Config.pm  |  4 +++-
 lib/PublicInbox/NewsWWW.pm |  3 ++-
 t/plack.t                  | 15 +++++++++++++++
 3 files changed, 20 insertions(+), 2 deletions(-)

diff --git a/lib/PublicInbox/Config.pm b/lib/PublicInbox/Config.pm
index 935b044..35b24af 100644
--- a/lib/PublicInbox/Config.pm
+++ b/lib/PublicInbox/Config.pm
@@ -56,7 +56,8 @@ sub lookup_name {
 	my ($self, $name) = @_;
 	my $rv = $self->{-by_name}->{$name};
 	return $rv if $rv;
-	$self->{-by_name}->{$name} = _fill($self, "publicinbox.$name");
+	$rv = _fill($self, "publicinbox.$name") or return;
+	$self->{-by_name}->{$name} = $rv;
 }
 
 sub get {
@@ -118,6 +119,7 @@ sub _fill {
 		my $v = $self->{"$pfx.$k"};
 		$rv->{$k} = $v if defined $v;
 	}
+	return unless $rv->{mainrepo};
 	my $inbox = $pfx;
 	$inbox =~ s/\Apublicinbox\.//;
 	$rv->{name} = $inbox;
diff --git a/lib/PublicInbox/NewsWWW.pm b/lib/PublicInbox/NewsWWW.pm
index 19eb596..5357059 100644
--- a/lib/PublicInbox/NewsWWW.pm
+++ b/lib/PublicInbox/NewsWWW.pm
@@ -30,7 +30,6 @@ sub call {
 	if (my $info = $ng_map->{$ng}) {
 		my $url = PublicInbox::Hval::prurl($env, $info->{url});
 		my $code = 301;
-		my $h = [ Location => $url, 'Content-Type' => 'text/plain' ];
 		if (defined $article && $article =~ /\A\d+\z/) {
 			my $mid = eval { ng_mid_for($ng, $info, $article) };
 			if (defined $mid) {
@@ -41,6 +40,8 @@ sub call {
 			}
 		}
 
+		my $h = [ Location => $url, 'Content-Type' => 'text/plain' ];
+
 		return [ $code, $h, [ "Redirecting to $url\n" ] ]
 	}
 	[ 404, [ 'Content-Type' => 'text/plain' ], [] ];
diff --git a/t/plack.t b/t/plack.t
index c8dd7bf..04680b2 100644
--- a/t/plack.t
+++ b/t/plack.t
@@ -30,6 +30,8 @@ foreach my $mod (@mods) { use_ok $mod; }
 	my %cfg = (
 		"$cfgpfx.address" => $addr,
 		"$cfgpfx.mainrepo" => $maindir,
+		"$cfgpfx.url" => 'http://example.com/test/',
+		"$cfgpfx.newsgroup" => 'inbox.test',
 	);
 	while (my ($k,$v) = each %cfg) {
 		is(0, system(qw(git config --file), $pi_config, $k, $v),
@@ -60,6 +62,19 @@ EOF
 		require $psgi;
 	};
 
+	# redirect with newsgroup
+	test_psgi($app, sub {
+		my ($cb) = @_;
+		my $from = 'http://example.com/inbox.test';
+		my $to = 'http://example.com/test/';
+		my $res = $cb->(GET($from));
+		is($res->code, 301, 'is permanent redirect');
+		is($to, $res->header('Location'), 'redirect location matches');
+		$from .= '/';
+		is($res->code, 301, 'is permanent redirect');
+		is($to, $res->header('Location'), 'redirect location matches');
+	});
+
 	# redirect with trailing /
 	test_psgi($app, sub {
 		my ($cb) = @_;

^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2016-05-27  9:06 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-05-27  9:06 [PATCH] config: fix NewsWWW fallback for newsgroups in HTTP URLs Eric Wong

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).