]> Sergey Matveev's repositories - public-inbox.git/blob - lib/PublicInbox/HTTPD.pm
47f5a01a786daa8e7d0c6bf859cfd417541aa7c3
[public-inbox.git] / lib / PublicInbox / HTTPD.pm
1 # Copyright (C) 2016-2019 all contributors <meta@public-inbox.org>
2 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
3
4 # wraps a listen socket for HTTP and links it to the PSGI app in
5 # public-inbox-httpd
6 package PublicInbox::HTTPD;
7 use strict;
8 use warnings;
9 use Plack::Util;
10 require PublicInbox::HTTPD::Async;
11 require PublicInbox::Daemon;
12
13 sub pi_httpd_async { PublicInbox::HTTPD::Async->new(@_) }
14
15 sub new {
16         my ($class, $sock, $app) = @_;
17         my $n = getsockname($sock) or die "not a socket: $sock $!\n";
18         my ($host, $port) = PublicInbox::Daemon::host_with_port($n);
19
20         my %env = (
21                 SERVER_NAME => $host,
22                 SERVER_PORT => $port,
23                 SCRIPT_NAME => '',
24                 'psgi.version' => [ 1, 1 ],
25                 'psgi.errors' => \*STDERR,
26                 'psgi.url_scheme' => 'http',
27                 'psgi.nonblocking' => Plack::Util::TRUE,
28                 'psgi.streaming' => Plack::Util::TRUE,
29                 'psgi.run_once'  => Plack::Util::FALSE,
30                 'psgi.multithread' => Plack::Util::FALSE,
31                 'psgi.multiprocess' => Plack::Util::TRUE,
32
33                 # We don't use this anywhere, but we can support
34                 # other PSGI apps which might use it:
35                 'psgix.input.buffered' => Plack::Util::TRUE,
36
37                 # XXX unstable API!, only GitHTTPBackend needs
38                 # this to limit git-http-backend(1) parallelism.
39                 # The rest of our PSGI code is generic, relying
40                 # on "pull" model using "getline" to prevent
41                 # over-buffering.
42                 'pi-httpd.async' => \&pi_httpd_async
43         );
44         bless {
45                 app => $app,
46                 env => \%env
47         }, $class;
48 }
49
50 1;