This is lighter and we can work further towards eliminating
our Plack::Request dependency entirely.
---
 lib/PublicInbox/Feed.pm      |  4 +---
 lib/PublicInbox/Inbox.pm     | 12 ++++++++----
 lib/PublicInbox/Mbox.pm      |  2 +-
 lib/PublicInbox/WWW.pm       |  2 +-
 lib/PublicInbox/WwwStream.pm |  9 ++-------
 t/view.t                     |  1 +
 6 files changed, 14 insertions(+), 16 deletions(-)

diff --git a/lib/PublicInbox/Feed.pm b/lib/PublicInbox/Feed.pm
index 2f141c4..ffbf5c8 100644
--- a/lib/PublicInbox/Feed.pm
+++ b/lib/PublicInbox/Feed.pm
@@ -297,13 +297,11 @@ sub get_feedopts {
        my $pi_config = $ctx->{pi_config};
        my $inbox = $ctx->{inbox};
        my $obj = $ctx->{-inbox};
-       my $cgi = $ctx->{cgi};
        my %rv = ( description => $obj->description );
 
        $rv{address} = $obj->{address};
        $rv{id_addr} = $obj->{-primary_address};
-       my $url_base;
-       $url_base = $obj->base_url($cgi); # CGI may be undef
+       my $url_base = $obj->base_url($ctx->{env});
        if (my $mid = $ctx->{mid}) { # per-thread feed:
                $rv{atomurl} = "$url_base$mid/t.atom";
        } else {
diff --git a/lib/PublicInbox/Inbox.pm b/lib/PublicInbox/Inbox.pm
index ada713c..96c9265 100644
--- a/lib/PublicInbox/Inbox.pm
+++ b/lib/PublicInbox/Inbox.pm
@@ -71,10 +71,14 @@ sub cloneurl {
 }
 
 sub base_url {
-       my ($self, $prq) = @_; # Plack::Request
-       if (defined $prq) {
-               my $url = $prq->base->as_string;
-               $url .= '/' if $url !~ m!/\z!; # for mount in Plack::Builder
+       my ($self, $env) = @_;
+       if ($env) { # PSGI env
+               my $scheme = $env->{'psgi.url_scheme'};
+               my $host_port = $env->{HTTP_HOST} ||
+                       "$env->{SERVER_NAME}:$env->{SERVER_PORT}";
+               my $url = "$scheme://$host_port". ($env->{SCRIPT_NAME} || '/');
+               # for mount in Plack::Builder
+               $url .= '/' if $url !~ m!/\z!;
                $url .= $self->{name} . '/';
        } else {
                # either called from a non-PSGI environment (e.g. NNTP/POP3)
diff --git a/lib/PublicInbox/Mbox.pm b/lib/PublicInbox/Mbox.pm
index 1c97f95..9dad0f6 100644
--- a/lib/PublicInbox/Mbox.pm
+++ b/lib/PublicInbox/Mbox.pm
@@ -28,7 +28,7 @@ sub msg_str {
                $header_obj->header_set($d);
        }
        my $ibx = $ctx->{-inbox};
-       my $base = $ibx->base_url($ctx->{cgi});
+       my $base = $ibx->base_url($ctx->{env});
        my $mid = mid_clean($header_obj->header('Message-ID'));
        $mid = uri_escape_utf8($mid);
        my @append = (
diff --git a/lib/PublicInbox/WWW.pm b/lib/PublicInbox/WWW.pm
index c4509bd..1e23c43 100644
--- a/lib/PublicInbox/WWW.pm
+++ b/lib/PublicInbox/WWW.pm
@@ -401,7 +401,7 @@ sub r301 {
                return $r404 if $r404;
                $obj = $ctx->{-inbox};
        }
-       my $url = $obj->base_url($cgi);
+       my $url = $obj->base_url($ctx->{env});
        my $qs = $ctx->{env}->{QUERY_STRING};
        $url .= (uri_escape_utf8($mid) . '/') if (defined $mid);
        $url .= $suffix if (defined $suffix);
diff --git a/lib/PublicInbox/WwwStream.pm b/lib/PublicInbox/WwwStream.pm
index fdab4da..be6ce2e 100644
--- a/lib/PublicInbox/WwwStream.pm
+++ b/lib/PublicInbox/WwwStream.pm
@@ -62,13 +62,8 @@ sub _html_end {
        my $obj = $ctx->{-inbox};
        my $desc = ascii_html($obj->description);
 
-       # FIXME: cleanup
-       my $env = $ctx->{env};
-       my $scheme = $env->{'psgi.url_scheme'};
-       my $host_port = $env->{HTTP_HOST} ||
-                       "$env->{SERVER_NAME}:$env->{SERVER_PORT}";
-       my $http = "$scheme://$host_port".($env->{SCRIPT_NAME} || '/');
-       $http = URI->new($http . $obj->{name})->canonical->as_string;
+       my $http = $obj->base_url($ctx->{env});
+       chop $http;
        my %seen = ( $http => 1 );
        my @urls = ($http);
        foreach my $u (@{$obj->cloneurl}) {
diff --git a/t/view.t b/t/view.t
index 4fdd151..4cee439 100644
--- a/t/view.t
+++ b/t/view.t
@@ -25,6 +25,7 @@ my $ctx = {
        -inbox => Plack::Util::inline_object(
                name => 'test',
                search => sub { undef },
+               base_url => sub { 'http://example.com/' },
                cloneurl => sub {[]},
                description => sub { '' }),
 };
-- 
EW

--
unsubscribe: meta+unsubscr...@public-inbox.org
archive: https://public-inbox.org/meta/

Reply via email to