]> Sergey Matveev's repositories - public-inbox.git/blob - lib/PublicInbox/HTTPD.pm
update copyrights for 2021
[public-inbox.git] / lib / PublicInbox / HTTPD.pm
1 # Copyright (C) 2016-2021 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 use PublicInbox::HTTPD::Async;
11 use 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                 # We also check for the truthiness of this to
40                 # detect when to use git_async_cat for slow blobs
41                 'pi-httpd.async' => \&pi_httpd_async
42         );
43         bless {
44                 app => $app,
45                 env => \%env
46         }, $class;
47 }
48
49 1;