2 # Copyright (C) 2016 all contributors <meta@public-inbox.org>
3 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
5 # Standalone HTTP server for public-inbox.
9 use PublicInbox::Daemon;
10 use PublicInbox::HTTP;
14 PublicInbox::WWW->preload;
15 my $have_deflater = eval { require Plack::Middleware::Deflater; 1 };
21 eval { $app = Plack::Util::load_psgi(@ARGV) };
24 "$0 runs in /, command-line paths must be absolute\n";
28 my $deflate_types = eval {
29 require Plack::Middleware::Deflater;
30 [ 'text/html', 'text/plain',
31 'application/atom+xml' ]
37 content_type => $deflate_types
41 my $req = Plack::Request->new(@_);
42 PublicInbox::WWW::run($req,
50 daemon_run('0.0.0.0:8080', $refresh,
51 sub ($$$) { # post_accept
52 my ($client, $addr, $srv) = @_;
53 my $fd = fileno($srv);
54 my $h = $httpds{$fd} ||= PublicInbox::HTTPD->new($srv, $app);
55 PublicInbox::HTTP->new($client, $addr, $h),
59 package PublicInbox::HTTPD;
65 my ($class, $sock, $app) = @_;
66 my $n = getsockname($sock) or die "not a socket: $sock $!\n";
68 if (length($n) >= 28) {
70 ($port, $addr) = Socket6::unpack_sockaddr_in6($n);
72 ($port, $addr) = Socket::unpack_sockaddr_in($n);
81 'psgi.version' => [ 1, 1 ],
82 'psgi.errors' => \*STDERR,
83 'psgi.url_scheme' => 'http',
84 'psgi.nonblocking' => Plack::Util::TRUE,
85 'psgi.streaming' => Plack::Util::TRUE,
86 'psgi.run_once' => Plack::Util::FALSE,
87 'psgi.multithread' => Plack::Util::FALSE,
88 'psgi.multiprocess' => Plack::Util::TRUE,
89 'psgix.harakiri'=> Plack::Util::FALSE,
90 'psgix.input.buffered' => Plack::Util::TRUE,