unofficial mirror of meta@public-inbox.org
 help / color / mirror / Atom feed
From: Eric Wong <e@80x24.org>
To: meta@public-inbox.org
Subject: [PATCH 6/6] www: remove Plack::Request dependency entirely
Date: Sat,  2 Jul 2016 07:56:38 +0000	[thread overview]
Message-ID: <20160702075638.31017-7-e@80x24.org> (raw)
In-Reply-To: <20160702075638.31017-1-e@80x24.org>

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 ffbf5c8..2983514 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 940e1c5..5425308 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 <a\nhref=\"" . $ssoma_url .
 			qq(">ssoma</a> or <b>git clone --mirror $urls[0]</b>);
@@ -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 f19582f..8ba42c2 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 b9eaa6f..5ecc69b 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 16f7bdd..ef827fc 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 0e19b56..c2e7360 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 a4f3245..40298e5 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 ef116c6..0d20b7f 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 c1c1b0c..dae45ba 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 $@;
-- 
EW


      parent reply	other threads:[~2016-07-02  7:56 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-07-02  7:56 [PATCH 0/6] misc cleanups Eric Wong
2016-07-02  7:56 ` [PATCH 1/6] TODO: clarify streaming Email::MIME replacement Eric Wong
2016-07-02  7:56 ` [PATCH 2/6] inbox: base_url method takes PSGI env hashref instead Eric Wong
2016-07-02  7:56 ` [PATCH 3/6] extmsg: rework to use Inbox objects Eric Wong
2016-07-02  7:56 ` [PATCH 4/6] www: use PSGI env directly Eric Wong
2016-07-02  7:56 ` [PATCH 5/6] view: rely on internal query parser for 'o' param Eric Wong
2016-07-02  7:56 ` Eric Wong [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://public-inbox.org/README

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20160702075638.31017-7-e@80x24.org \
    --to=e@80x24.org \
    --cc=meta@public-inbox.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).