user/dev discussion of public-inbox itself
 help / color / mirror / code / Atom feed
From: Eric Wong <e@80x24.org>
To: Konstantin Ryabitsev <konstantin@linuxfoundation.org>
Cc: meta@public-inbox.org
Subject: [PATCH v2] examples/newswww.psgi: demonstrate standalone NewsWWW usage
Date: Mon, 4 Feb 2019 11:11:48 +0000	[thread overview]
Message-ID: <20190204111148.asdznzud6oblg3h4@dcvr> (raw)
In-Reply-To: <20190201183113.kacp665geshxxmin@dcvr>

Eric Wong <e@80x24.org> wrote:
> Or just use NewsWWW, because nntp://<HOSTNAME>/<Message-ID> is valid.
> Going to think about it while I eat and do other things, but
> will very likely merge it to master, soon.

Yep.  It's in NewsWWW, now.  Also going to add this.  I think
it'll be helpful for nntp.lore.kernel.org to have this on 80/443
because somebody could share NNTP URLs and some software
somewhere will interpret it as "HTTP"

--------8<-------
Subject: [PATCH] examples/newswww.psgi: demonstrate standalone NewsWWW usage

Plack::Builder allows "mounting" on with hostnames as well as
path names to enable virtual hosting.  This example demonstrates
how port 80/443 for "news.example.com" can redirect browser
requests when somebody attempts to use a "nntp://" URL and
the software assumes "http://"
---
 examples/newswww.psgi | 48 +++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 48 insertions(+)
 create mode 100644 examples/newswww.psgi

diff --git a/examples/newswww.psgi b/examples/newswww.psgi
new file mode 100644
index 0000000..0f66782
--- /dev/null
+++ b/examples/newswww.psgi
@@ -0,0 +1,48 @@
+#!/usr/bin/perl -w
+# Copyright (C) 2019 all contributors <meta@public-inbox.org>
+# License: GPL-3.0+ <https://www.gnu.org/licenses/gpl-3.0.txt>
+#
+# NewsWWW may be used independently of WWW.  This can be useful
+# for mapping HTTP/HTTPS requests to the hostname of an NNTP server
+# to redirect users to the proper HTTP/HTTPS endpoint for a given
+# inbox.  NewsWWW exists because people (or software) can mishandle
+# "nntp://" or "news://" URLs as "http://" (or "https://")
+#
+# Usage:
+#	plackup -I lib -o 127.0.0.1 -R lib -r examples/newswww.psgi
+use strict;
+use warnings;
+use Plack::Builder;
+use PublicInbox::WWW;
+use PublicInbox::NewsWWW;
+
+my $newswww = PublicInbox::NewsWWW->new;
+
+# Optional, (you may drop the "mount '/'" section below)
+my $www = PublicInbox::WWW->new;
+$www->preload;
+
+builder {
+	# HTTP/1.1 requests to "Host: news.example.com" will hit this:
+	mount 'http://news.example.com/' => builder {
+		enable 'Head';
+		sub { $newswww->call($_[0]) };
+	};
+
+	# rest of requests will hit this (optional) part for the
+	# regular PublicInbox::WWW code:
+	# see comments in examples/public-inbox.psgi for more info:
+	mount '/' => builder {
+		eval {
+			enable 'Deflater',
+				content_type => [ qw(
+					text/html
+					text/plain
+					application/atom+xml
+					)]
+		};
+		eval { enable 'ReverseProxy' };
+		enable 'Head';
+		sub { $www->call($_[0]) }
+	};
+}
-- 
EW

  reply	other threads:[~2019-02-04 11:11 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-01-09 11:43 [RFC 0/2] support for /~/$MESSAGE_ID endpoint Eric Wong
2019-01-09 11:43 ` [RFC 1/2] config: inbox name checking matches git.git more closely Eric Wong
2019-01-09 11:43 ` [RFC 2/2] www: add /~/$MESSAGE_ID global redirector endpoint Eric Wong
2019-01-27  2:06   ` Eric Wong
2019-01-28 13:50     ` Konstantin Ryabitsev
2019-02-01  9:00       ` Eric Wong
2019-02-01 18:31         ` [PATCH v2] newswww: add /$MESSAGE_ID " Eric Wong
2019-02-04 11:11           ` Eric Wong [this message]
2019-02-19 19:53         ` [RFC 2/2] www: add /~/$MESSAGE_ID " Konstantin Ryabitsev
2019-02-19 22:55           ` Eric Wong

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: http://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=20190204111148.asdznzud6oblg3h4@dcvr \
    --to=e@80x24.org \
    --cc=konstantin@linuxfoundation.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.
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).