user/dev discussion of public-inbox itself
 help / color / mirror / code / Atom feed
* [PATCH] hval: implement common UI for protocol-relative URLs
@ 2016-02-25  3:57 Eric Wong
  0 siblings, 0 replies; only message in thread
From: Eric Wong @ 2016-02-25  3:57 UTC (permalink / raw)
  To: meta

This allows users to avoid HTTPS -> HTTP downgrade warnings,
but we will also avoid encouraging them towards HTTPS, for now.

IMHO: the CA system gives a false sense of security,
TLS libraries (e.g. OpenSSL) can introduce new bugs and
problems (even to attack clients), and TLS libraries
also eats memory on cheap servers.
---
 lib/PublicInbox/ExtMsg.pm     |  4 ++--
 lib/PublicInbox/Hval.pm       |  5 +++++
 lib/PublicInbox/SearchView.pm |  7 ++++---
 lib/PublicInbox/WWW.pm        | 16 ++++++++++------
 4 files changed, 21 insertions(+), 11 deletions(-)

diff --git a/lib/PublicInbox/ExtMsg.pm b/lib/PublicInbox/ExtMsg.pm
index cf9b6d5..c6fc565 100644
--- a/lib/PublicInbox/ExtMsg.pm
+++ b/lib/PublicInbox/ExtMsg.pm
@@ -137,9 +137,9 @@ again:
 	if (@EXT_URL && index($mid, '@') >= 0) {
 		$code = 300;
 		$s .= "\nPerhaps try an external site:\n\n";
-		my $scheme = $cgi->scheme;
+		my $env = $cgi->{env};
 		foreach my $u (@EXT_URL) {
-			$u = "$scheme:$u" if $u =~ m!\A//!;
+			$u = PublicInbox::Hval::prurl($env, $u);
 			my $r = sprintf($u, $href);
 			my $t = sprintf($u, $html);
 			$s .= qq{<a\nhref="$r">$t</a>\n};
diff --git a/lib/PublicInbox/Hval.pm b/lib/PublicInbox/Hval.pm
index d295f5c..a455884 100644
--- a/lib/PublicInbox/Hval.pm
+++ b/lib/PublicInbox/Hval.pm
@@ -69,4 +69,9 @@ sub raw {
 	}
 }
 
+sub prurl {
+	my ($env, $u) = @_;
+	index($u, '//') == 0 ? "$env->{'psgi.url_scheme'}:$u" : $u;
+}
+
 1;
diff --git a/lib/PublicInbox/SearchView.pm b/lib/PublicInbox/SearchView.pm
index 8f61b4f..746cb83 100644
--- a/lib/PublicInbox/SearchView.pm
+++ b/lib/PublicInbox/SearchView.pm
@@ -35,7 +35,7 @@ sub sres_top_html {
 	my $res = html_start($q, $ctx) . '<pre>';
 	if ($err) {
 		$code = 400;
-		$res .= err_txt($err) . "</pre><hr /><pre>" . foot($ctx);
+		$res .= err_txt($ctx, $err) . "</pre><hr /><pre>" . foot($ctx);
 	} elsif ($total == 0) {
 		$code = 404;
 		$res .= "\n\n[No results found]</pre><hr /><pre>".foot($ctx);
@@ -80,8 +80,9 @@ sub dump_mset {
 }
 
 sub err_txt {
-	my ($err) = @_;
-	my $u = 'http://xapian.org/docs/queryparser.html';
+	my ($ctx, $err) = @_;
+	my $u = '//xapian.org/docs/queryparser.html';
+	$u = PublicInbox::Hval::prurl($ctx->{cgi}->{env}, $u);
 	$err =~ s/^\s*Exception:\s*//; # bad word to show users :P
 	$err = PublicInbox::Hval->new_oneline($err)->as_html;
 	"\n\nBad query: <b>$err</b>\n" .
diff --git a/lib/PublicInbox/WWW.pm b/lib/PublicInbox/WWW.pm
index e87e559..8372927 100644
--- a/lib/PublicInbox/WWW.pm
+++ b/lib/PublicInbox/WWW.pm
@@ -15,8 +15,8 @@ use strict;
 use warnings;
 use PublicInbox::Config qw(try_cat);
 use URI::Escape qw(uri_escape_utf8 uri_unescape);
-use constant SSOMA_URL => 'http://ssoma.public-inbox.org/';
-use constant PI_URL => 'http://public-inbox.org/';
+use constant SSOMA_URL => '//ssoma.public-inbox.org/';
+use constant PI_URL => '//public-inbox.org/';
 require PublicInbox::Git;
 use PublicInbox::GitHTTPBackend;
 our $LISTNAME_RE = qr!\A/([\w\.\-]+)!;
@@ -264,14 +264,16 @@ sub footer {
 	my $urls = try_cat("$git_dir/cloneurl");
 	my @urls = split(/\r?\n/, $urls || '');
 	my %seen = map { $_ => 1 } @urls;
-	my $http = $ctx->{cgi}->base->as_string . $listname;
+	my $cgi = $ctx->{cgi};
+	my $http = $cgi->base->as_string . $listname;
 	$seen{$http} or unshift @urls, $http;
+	my $ssoma_url = PublicInbox::Hval::prurl($cgi->{env}, SSOMA_URL);
 	if (scalar(@urls) == 1) {
-		$urls = "URL for <a\nhref=\"" . SSOMA_URL .
+		$urls = "URL for <a\nhref=\"" . $ssoma_url .
 			qq(">ssoma</a> or <b>git clone --mirror \$URL</b> :) .
 			$urls[0];
 	} else {
-		$urls = "URLs for <a\nhref=\"" . SSOMA_URL .
+		$urls = "URLs for <a\nhref=\"" . $ssoma_url .
 			qq(">ssoma</a> or <b>git clone --mirror \$URL</b>\n) .
 			join("\n", map { "\t$_" } @urls);
 	}
@@ -285,7 +287,9 @@ sub footer {
 
 	$ctx->{footer} = join("\n",
 		'- ' . $desc,
-		"A <a\nhref=\"" . PI_URL .  '">public-inbox</a>, ' .
+		"A <a\nhref=\"" .
+			PublicInbox::Hval::prurl($ctx->{cgi}->{env}, PI_URL) .
+			'">public-inbox</a>, ' .
 			'anybody may post in plain-text (not HTML):',
 		$addr,
 		$urls
-- 
EW


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

only message in thread, other threads:[~2016-02-25  3:57 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-02-25  3:57 [PATCH] hval: implement common UI for protocol-relative URLs Eric Wong

Code repositories for project(s) associated with this public inbox

	https://80x24.org/public-inbox.git

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).