]> Sergey Matveev's repositories - public-inbox.git/blob - lib/PublicInbox/HTTPD.pm
split out NNTPD and HTTPD* modules
[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 {
12         my ($io, $cb) = @_;
13         PublicInbox::HTTPD::Async->new($io, $cb);
14 }
15
16 sub new {
17         my ($class, $sock, $app) = @_;
18         my $n = getsockname($sock) or die "not a socket: $sock $!\n";
19         my ($host, $port) = PublicInbox::Daemon::host_with_port($n);
20
21         my %env = (
22                 SERVER_NAME => $host,
23                 SERVER_PORT => $port,
24                 SCRIPT_NAME => '',
25                 'psgi.version' => [ 1, 1 ],
26                 'psgi.errors' => \*STDERR,
27                 'psgi.url_scheme' => 'http',
28                 'psgi.nonblocking' => Plack::Util::TRUE,
29                 'psgi.streaming' => Plack::Util::TRUE,
30                 'psgi.run_once'  => Plack::Util::FALSE,
31                 'psgi.multithread' => Plack::Util::FALSE,
32                 'psgi.multiprocess' => Plack::Util::TRUE,
33                 'psgix.harakiri'=> Plack::Util::FALSE,
34                 'psgix.input.buffered' => Plack::Util::TRUE,
35                 'pi-httpd.async' => do {
36                         no warnings 'once';
37                         *pi_httpd_async
38                 },
39         );
40         bless {
41                 app => $app,
42                 env => \%env
43         }, $class;
44 }
45
46 1;