require PublicInbox::WWW;
PublicInbox::WWW->preload;
my $www = PublicInbox::WWW->new;
- $app = eval {
- my $deflate_types = eval {
- require Plack::Middleware::Deflater;
- [ 'text/html', 'text/plain',
- 'application/atom+xml' ]
- };
- builder {
- enable 'Chunked';
- if ($deflate_types) {
- enable 'Deflater',
- content_type => $deflate_types
- }
- enable 'ReverseProxy';
- enable 'Head';
- sub { $www->call(@_) };
+ $app = builder {
+ enable 'Chunked';
+ eval {
+ enable 'Deflater',
+ content_type => [ qw(
+ text/html
+ text/plain
+ application/atom+xml
+ )]
};
+ $@ and warn
+"Plack::Middleware::Deflater missing, bandwidth will be wasted\n";
+
+ eval { enable 'ReverseProxy' };
+ $@ and warn
+"Plack::Middleware::ReverseProxy missing,\n",
+"URL generation for redirects may be wrong if behind a reverse proxy\n";
+
+ enable 'Head';
+ sub { $www->call(@_) };
};
}
};
-daemon_run('0.0.0.0:8080', $refresh,
+PublicInbox::Daemon::run('0.0.0.0:8080', $refresh,
sub ($$$) { # post_accept
my ($client, $addr, $srv) = @_;
my $fd = fileno($srv);
1;
+# XXX This is a totally unstable API for public-inbox internal use only
+# This is exposed via the 'pi-httpd.async' key in the PSGI env hash.
+# The name of this key is not even stable!
+# Currently is is intended for use with read-only pipes.
package PublicInbox::HTTPD::Async;
use strict;
use warnings;
sub new {
my ($class, $io, $cb) = @_;
my $self = fields::new($class);
- $io->blocking(0);
+ IO::Handle::blocking($io, 0);
$self->SUPER::new($io);
$self->{cb} = $cb;
$self->watch_read(1);
sub new {
my ($class, $sock, $app) = @_;
my $n = getsockname($sock) or die "not a socket: $sock $!\n";
- my ($port, $addr);
- if (length($n) >= 28) {
- require Socket6;
- ($port, $addr) = Socket6::unpack_sockaddr_in6($n);
- } else {
- ($port, $addr) = Socket::unpack_sockaddr_in($n);
- }
+ my ($host, $port) = PublicInbox::Daemon::host_with_port($n);
my %env = (
- REMOTE_HOST => '',
- REMOTE_PORT => 0,
- SERVER_NAME => $addr,
+ SERVER_NAME => $host,
SERVER_PORT => $port,
SCRIPT_NAME => '',
'psgi.version' => [ 1, 1 ],
},
);
bless {
- err => \*STDERR,
- out => \*STDOUT,
app => $app,
env => \%env,
}, $class;