about summary refs log tree commit homepage
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2014-04-28 04:56:47 +0000
committerEric Wong <e@80x24.org>2014-04-28 04:56:47 +0000
commitebbd4ea1b468d80f7ddd446ed1e14961b62e8c03 (patch)
tree78169a2bfc2b5cf8730d787cdb14b8901ee3c6ef
parent59e7af124580f46bdb2dec21273607599ba1e8f9 (diff)
downloadpublic-inbox-ebbd4ea1b468d80f7ddd446ed1e14961b62e8c03.tar.gz
This might be slightly cleaner, though generating the base URL
now has an ugly condition in it.
-rw-r--r--lib/PublicInbox/Feed.pm21
-rwxr-xr-xpublic-inbox.cgi30
2 files changed, 26 insertions, 25 deletions
diff --git a/lib/PublicInbox/Feed.pm b/lib/PublicInbox/Feed.pm
index bddba912..22070370 100644
--- a/lib/PublicInbox/Feed.pm
+++ b/lib/PublicInbox/Feed.pm
@@ -109,16 +109,13 @@ sub nav_footer {
         my $old_r = $cgi->param('r');
         my $prev = '    ';
         my $next = '    ';
-        my %opts = (-path => 1, -query => 1, -relative => 1);
 
         if ($last) {
-                $cgi->param('r', $last);
-                $next = $cgi->url(%opts);
+                $next = $cgi->path_info . "?r=$last";
                 $next = qq!<a href="$next">next</a>!;
         }
         if ($first && $old_r) {
-                $cgi->param('r', "$first..");
-                $prev = $cgi->url(%opts);
+                $prev = $cgi->path_info . "?r=$first..";
                 $prev = qq!<a href="$prev">prev</a>!;
         }
         "$prev $next";
@@ -213,14 +210,20 @@ sub get_feedopts {
         }
         my $url_base;
         if ($cgi) {
-                my $cgi_url = $cgi->url(-path=>1, -relative=>1);
-                my $base = $cgi->url(-base);
-                $url_base = $cgi_url;
+                my $path_info = $cgi->path_info;
+                my $base;
+                if (ref($cgi) eq 'CGI') {
+                        $base = $cgi->url(-base);
+                } else {
+                        $base = "${$cgi->base}";
+                        $base =~ s!/\z!!;
+                }
+                $url_base = $path_info;
                 if ($url_base =~ s!/(?:|index\.html)?\z!!) {
                         $rv{atomurl} = "$base$url_base/atom.xml";
                 } else {
                         $url_base =~ s!/atom\.xml\z!!;
-                        $rv{atomurl} = $base . $cgi_url;
+                        $rv{atomurl} = $base . $path_info;
                         $url_base = $base . $url_base; # XXX is this needed?
                 }
         } else {
diff --git a/public-inbox.cgi b/public-inbox.cgi
index 87cc6943..7f7e59ca 100755
--- a/public-inbox.cgi
+++ b/public-inbox.cgi
@@ -30,7 +30,13 @@ BEGIN {
 if ($ENV{PI_PLACKUP}) {
         psgi_app();
 } else {
-        my $ret = main();
+        # some servers (Ruby webrick) include scheme://host[:port] here,
+        # which confuses CGI.pm when generating self_url.
+        # RFC 3875 does not mention REQUEST_URI at all,
+        # so nuke it since CGI.pm functions without it.
+        delete $ENV{REQUEST_URI};
+        my $req = CGI->new;
+        my $ret = main($req, $req->request_method);
         binmode STDOUT;
         if (@ARGV && $ARGV[0] eq 'static') {
                 print $ret->[2]->[0];
@@ -42,15 +48,9 @@ if ($ENV{PI_PLACKUP}) {
 # private functions below
 
 sub main {
-        # some servers (Ruby webrick) include scheme://host[:port] here,
-        # which confuses CGI.pm when generating self_url.
-        # RFC 3875 does not mention REQUEST_URI at all,
-        # so nuke it since CGI.pm functions without it.
-        delete $ENV{REQUEST_URI};
-
-        my $cgi = CGI->new;
+        my ($cgi, $method) = @_;
         my %ctx;
-        if ($cgi->request_method !~ /\AGET|HEAD\z/) {
+        if ($method !~ /\AGET|HEAD\z/) {
                 return r(405, 'Method Not Allowed');
         }
         my $path_info = $enc_utf8->decode($cgi->path_info);
@@ -205,8 +205,6 @@ sub do_redirect {
 }
 
 sub psgi_app {
-        require CGI::Emulate::PSGI;
-
         # preload so we are CoW friendly
         require PublicInbox::Feed;
         require PublicInbox::View;
@@ -214,12 +212,12 @@ sub psgi_app {
         require Digest::SHA;
         require POSIX;
         require XML::Atom::SimpleFeed;
-        eval { require Git };
+        require Plack::Request;
+        eval { require Git }; # optional
         sub {
-                my ($e) = @_;
-                local %ENV = (%ENV, CGI::Emulate::PSGI->emulate_environment($e));
-                main();
-        }
+                my $req = Plack::Request->new(@_);
+                main($req, $req->method);
+        };
 }
 
 sub cgi_print {