]> Sergey Matveev's repositories - public-inbox.git/blob - lib/PublicInbox/HTTPD.pm
www: label sections and hopefully improve navigation
[public-inbox.git] / lib / PublicInbox / HTTPD.pm
1 # Copyright (C) 2016 all contributors <meta@public-inbox.org>
2 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
3
4 package PublicInbox::HTTPD;
5 use strict;
6 use warnings;
7 use Plack::Util;
8 require PublicInbox::HTTPD::Async;
9 require PublicInbox::Daemon;
10
11 sub pi_httpd_async { PublicInbox::HTTPD::Async->new(@_) }
12
13 sub new {
14         my ($class, $sock, $app) = @_;
15         my $n = getsockname($sock) or die "not a socket: $sock $!\n";
16         my ($host, $port) = PublicInbox::Daemon::host_with_port($n);
17
18         my %env = (
19                 SERVER_NAME => $host,
20                 SERVER_PORT => $port,
21                 SCRIPT_NAME => '',
22                 'psgi.version' => [ 1, 1 ],
23                 'psgi.errors' => \*STDERR,
24                 'psgi.url_scheme' => 'http',
25                 'psgi.nonblocking' => Plack::Util::TRUE,
26                 'psgi.streaming' => Plack::Util::TRUE,
27                 'psgi.run_once'  => Plack::Util::FALSE,
28                 'psgi.multithread' => Plack::Util::FALSE,
29                 'psgi.multiprocess' => Plack::Util::TRUE,
30                 'psgix.harakiri'=> Plack::Util::FALSE,
31                 'psgix.input.buffered' => Plack::Util::TRUE,
32                 'pi-httpd.async' => do {
33                         no warnings 'once';
34                         *pi_httpd_async
35                 },
36         );
37         bless {
38                 app => $app,
39                 env => \%env
40         }, $class;
41 }
42
43 1;