X-Git-Url: http://www.git.stargrave.org/?a=blobdiff_plain;f=script%2Fpublic-inbox-httpd;h=a4dd809916c5116db301ec30c65f0919a48517ec;hb=7e4bd71efcf3bf61216ec1a7577e33be5f95b8a9;hp=43f1818861ed1d10f0032ec3891029e4ff79a2c3;hpb=3d41aa23f35501ca92aab8aa42980fa73f7fa74f;p=public-inbox.git
diff --git a/script/public-inbox-httpd b/script/public-inbox-httpd
index 43f18188..a4dd8099 100755
--- a/script/public-inbox-httpd
+++ b/script/public-inbox-httpd
@@ -1,16 +1,21 @@
#!/usr/bin/perl -w
-# Copyright (C) 2016-2018 all contributors
+# Copyright (C) 2016-2021 all contributors
# License: AGPL-3.0+
#
# Standalone HTTP server for public-inbox.
use strict;
-use warnings;
-use Plack::Util;
+use v5.10.1;
use PublicInbox::Daemon;
-use PublicInbox::HTTP;
-use PublicInbox::HTTPD;
-use Plack::Builder;
-my %httpds;
+BEGIN {
+ for (qw(Plack::Builder Plack::Util)) {
+ eval("require $_") or die "E: Plack is required for $0\n";
+ }
+ Plack::Builder->import;
+ require PublicInbox::HTTP;
+ require PublicInbox::HTTPD;
+}
+
+my %httpds; # per-listen-FD mapping for HTTPD->{env}->{SERVER_}
my $app;
my $refresh = sub {
if (@ARGV) {
@@ -21,20 +26,9 @@ my $refresh = sub {
}
} else {
require PublicInbox::WWW;
- PublicInbox::WWW->preload;
my $www = PublicInbox::WWW->new;
+ $www->preload;
$app = builder {
- eval {
- enable 'Deflater',
- content_type => [ qw(
- text/html
- text/plain
- application/atom+xml
- )]
- };
- $@ and warn
-"Plack::Middleware::Deflater missing, bandwidth will be wasted\n";
-
eval { enable 'ReverseProxy' };
$@ and warn
"Plack::Middleware::ReverseProxy missing,\n",
@@ -44,12 +38,14 @@ my $refresh = sub {
sub { $www->call(@_) };
};
}
+ %httpds = (); # invalidate cache
};
PublicInbox::Daemon::run('0.0.0.0:8080', $refresh,
- sub ($$$) { # post_accept
- my ($client, $addr, $srv) = @_;
+ sub ($$$) { # Listener->{post_accept}
+ my ($client, $addr, $srv, $tls_wrap) = @_;
my $fd = fileno($srv);
- my $h = $httpds{$fd} ||= PublicInbox::HTTPD->new($srv, $app);
+ my $h = $httpds{$fd} //=
+ PublicInbox::HTTPD->new($srv, $app, $client);
PublicInbox::HTTP->new($client, $addr, $h),
});