From 193e9a586d49fb111fd201f491b1ad0be4e386b3 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Sat, 2 Jul 2016 07:56:38 +0000 Subject: www: remove Plack::Request dependency entirely Lighter and ever-so-slightly faster! Most importantly, this won't do non-obvious stuff behind our backs like trying to parse a POST request body for a query string param. --- lib/PublicInbox/Feed.pm | 9 +++++---- lib/PublicInbox/WWW.pm | 13 +++++-------- script/public-inbox-httpd | 1 - t/httpd-corner.t | 2 +- t/httpd-unix.t | 2 +- t/httpd.t | 2 +- t/plack.t | 2 +- t/psgi_attach.t | 2 +- t/psgi_mount.t | 2 +- 9 files changed, 16 insertions(+), 19 deletions(-) diff --git a/lib/PublicInbox/Feed.pm b/lib/PublicInbox/Feed.pm index ffbf5c80..2983514c 100644 --- a/lib/PublicInbox/Feed.pm +++ b/lib/PublicInbox/Feed.pm @@ -119,17 +119,18 @@ sub end_feed { sub emit_atom_thread { my ($cb, $ctx) = @_; - my $res = $ctx->{srch}->get_thread($ctx->{mid}); + my $mid = $ctx->{mid}; + my $res = $ctx->{srch}->get_thread($mid); return _no_thread($cb) unless $res->{total}; my $feed_opts = get_feedopts($ctx); my $fh = $cb->([200, ['Content-Type' => 'application/atom+xml']]); + my $ibx = $ctx->{-inbox}; + my $html_url = $ibx->base_url($ctx->{env}); + $html_url .= PublicInbox::Hval->new_msgid($mid)->as_href; - my $html_url = $feed_opts->{atomurl} = $ctx->{self_url}; - $html_url =~ s!/t\.atom\z!/!; $feed_opts->{url} = $html_url; $feed_opts->{emit_header} = 1; - my $ibx = $ctx->{-inbox}; foreach my $msg (@{$res->{msgs}}) { my $s = feed_entry($feed_opts, mid2path($msg->mid), $ibx); $fh->write($s) if defined $s; diff --git a/lib/PublicInbox/WWW.pm b/lib/PublicInbox/WWW.pm index 940e1c51..54253086 100644 --- a/lib/PublicInbox/WWW.pm +++ b/lib/PublicInbox/WWW.pm @@ -13,7 +13,6 @@ package PublicInbox::WWW; use 5.008; use strict; use warnings; -use Plack::Request; use PublicInbox::Config; use PublicInbox::Hval; use URI::Escape qw(uri_escape_utf8 uri_unescape); @@ -40,9 +39,7 @@ sub run { sub call { my ($self, $env) = @_; - my $cgi = Plack::Request->new($env); - my $ctx = { cgi => $cgi, env => $env, www => $self, - pi_config => $self->{pi_config} }; + my $ctx = { env => $env, www => $self, pi_config => $self->{pi_config} }; # we don't care about multi-value my %qp = map { @@ -267,10 +264,11 @@ sub footer { my $urls; my @urls = @{$obj->cloneurl}; my %seen = map { $_ => 1 } @urls; - my $cgi = $ctx->{cgi}; - my $http = $cgi->base->as_string . $obj->{name}; + my $env = $ctx->{env}; + my $http = $obj->base_url($env); + chop $http; $seen{$http} or unshift @urls, $http; - my $ssoma_url = PublicInbox::Hval::prurl($ctx->{env}, SSOMA_URL); + my $ssoma_url = PublicInbox::Hval::prurl($env, SSOMA_URL); if (scalar(@urls) == 1) { $urls = "URL for ssoma or git clone --mirror $urls[0]); @@ -329,7 +327,6 @@ sub get_thread_mbox { sub get_thread_atom { my ($ctx) = @_; searcher($ctx) or return need_search($ctx); - $ctx->{self_url} = $ctx->{cgi}->uri->as_string; require PublicInbox::Feed; PublicInbox::Feed::generate_thread_atom($ctx); } diff --git a/script/public-inbox-httpd b/script/public-inbox-httpd index f19582fa..8ba42c2f 100755 --- a/script/public-inbox-httpd +++ b/script/public-inbox-httpd @@ -9,7 +9,6 @@ use Plack::Util; use PublicInbox::Daemon; use PublicInbox::HTTP; use PublicInbox::HTTPD; -use Plack::Request; use Plack::Builder; my %httpds; my $app; diff --git a/t/httpd-corner.t b/t/httpd-corner.t index b9eaa6fb..5ecc69b5 100644 --- a/t/httpd-corner.t +++ b/t/httpd-corner.t @@ -7,7 +7,7 @@ use warnings; use Test::More; use Time::HiRes qw(gettimeofday tv_interval); -foreach my $mod (qw(Plack::Util Plack::Request Plack::Builder Danga::Socket +foreach my $mod (qw(Plack::Util Plack::Builder Danga::Socket HTTP::Date HTTP::Status)) { eval "require $mod"; plan skip_all => "$mod missing for httpd-corner.t" if $@; diff --git a/t/httpd-unix.t b/t/httpd-unix.t index 16f7bdd2..ef827fc6 100644 --- a/t/httpd-unix.t +++ b/t/httpd-unix.t @@ -5,7 +5,7 @@ use strict; use warnings; use Test::More; -foreach my $mod (qw(Plack::Util Plack::Request Plack::Builder Danga::Socket +foreach my $mod (qw(Plack::Util Plack::Builder Danga::Socket HTTP::Date HTTP::Status)) { eval "require $mod"; plan skip_all => "$mod missing for httpd-unix.t" if $@; diff --git a/t/httpd.t b/t/httpd.t index 0e19b568..c2e73608 100644 --- a/t/httpd.t +++ b/t/httpd.t @@ -4,7 +4,7 @@ use strict; use warnings; use Test::More; -foreach my $mod (qw(Plack::Util Plack::Request Plack::Builder Danga::Socket +foreach my $mod (qw(Plack::Util Plack::Builder Danga::Socket HTTP::Date HTTP::Status)) { eval "require $mod"; plan skip_all => "$mod missing for httpd.t" if $@; diff --git a/t/plack.t b/t/plack.t index a4f32457..40298e58 100644 --- a/t/plack.t +++ b/t/plack.t @@ -11,7 +11,7 @@ my $pi_config = "$tmpdir/config"; my $maindir = "$tmpdir/main.git"; my $addr = 'test-public@example.com'; my $cfgpfx = "publicinbox.test"; -my @mods = qw(HTTP::Request::Common Plack::Request Plack::Test +my @mods = qw(HTTP::Request::Common Plack::Test Mail::Thread URI::Escape); foreach my $mod (@mods) { eval "require $mod"; diff --git a/t/psgi_attach.t b/t/psgi_attach.t index ef116c6a..0d20b7f7 100644 --- a/t/psgi_attach.t +++ b/t/psgi_attach.t @@ -9,7 +9,7 @@ my $tmpdir = tempdir('psgi-attach-XXXXXX', TMPDIR => 1, CLEANUP => 1); my $maindir = "$tmpdir/main.git"; my $addr = 'test-public@example.com'; my $cfgpfx = "publicinbox.test"; -my @mods = qw(HTTP::Request::Common Plack::Request Plack::Test URI::Escape); +my @mods = qw(HTTP::Request::Common Plack::Test URI::Escape); foreach my $mod (@mods) { eval "require $mod"; plan skip_all => "$mod missing for plack.t" if $@; diff --git a/t/psgi_mount.t b/t/psgi_mount.t index c1c1b0c6..dae45baf 100644 --- a/t/psgi_mount.t +++ b/t/psgi_mount.t @@ -9,7 +9,7 @@ my $tmpdir = tempdir('psgi-path-XXXXXX', TMPDIR => 1, CLEANUP => 1); my $maindir = "$tmpdir/main.git"; my $addr = 'test-public@example.com'; my $cfgpfx = "publicinbox.test"; -my @mods = qw(HTTP::Request::Common Plack::Request Plack::Test URI::Escape); +my @mods = qw(HTTP::Request::Common Plack::Test URI::Escape); foreach my $mod (@mods) { eval "require $mod"; plan skip_all => "$mod missing for plack.t" if $@; -- cgit v1.2.3-24-ge0c7