]> Sergey Matveev's repositories - public-inbox.git/blob - lib/PublicInbox/HTTPD.pm
fb476624dbbb8b42837958e7e211daadbd145563
[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
33                 # XXX unstable API!
34                 'pi-httpd.async' => do {
35                         no warnings 'once';
36                         *pi_httpd_async
37                 },
38         );
39         bless {
40                 app => $app,
41                 env => \%env
42         }, $class;
43 }
44
45 1;