sub pi_httpd_async { PublicInbox::HTTPD::Async->new(@_) }
sub new {
- my ($class, $sock, $app) = @_;
+ my ($class, $sock, $app, $client) = @_;
my $n = getsockname($sock) or die "not a socket: $sock $!\n";
my ($host, $port) = PublicInbox::Daemon::host_with_port($n);
SCRIPT_NAME => '',
'psgi.version' => [ 1, 1 ],
'psgi.errors' => \*STDERR,
- 'psgi.url_scheme' => 'http',
+ 'psgi.url_scheme' => $client->can('accept_SSL') ?
+ 'https' : 'http',
'psgi.nonblocking' => Plack::Util::TRUE,
'psgi.streaming' => Plack::Util::TRUE,
'psgi.run_once' => Plack::Util::FALSE,
};
PublicInbox::Daemon::run('0.0.0.0:8080', $refresh,
- sub ($$$) { # post_accept
- my ($client, $addr, $srv) = @_;
+ sub ($$$) { # Listener->{post_accept}
+ my ($client, $addr, $srv, $tls_wrap) = @_;
my $fd = fileno($srv);
- my $h = $httpds{$fd} //= PublicInbox::HTTPD->new($srv, $app);
+ my $h = $httpds{$fd} //=
+ PublicInbox::HTTPD->new($srv, $app, $client);
PublicInbox::HTTP->new($client, $addr, $h),
});
} elsif ($path eq '/pid') {
$code = 200;
push @$body, "$$\n";
+ } elsif ($path eq '/url_scheme') {
+ $code = 200;
+ push @$body, $env->{'psgi.url_scheme'}
}
-
[ $code, $h, $body ]
};
# normal HTTPS
my $c = tcp_connect($https);
IO::Socket::SSL->start_SSL($c, %o);
- ok($c->print("GET /empty HTTP/1.1\r\n\r\nHost: example.com\r\n\r\n"),
- 'wrote HTTP request');
+ $c->print("GET /url_scheme HTTP/1.1\r\n\r\nHost: example.com\r\n\r\n")
+ or xbail "failed to write HTTP request: $!";
my $buf = '';
- sysread($c, $buf, 2007, length($buf)) until $buf =~ /\r\n\r\n/;
+ sysread($c, $buf, 2007, length($buf)) until $buf =~ /\r\n\r\nhttps?/;
like($buf, qr!\AHTTP/1\.1 200!, 'read HTTP response');
+ like($buf, qr!\r\nhttps\z!, "psgi.url_scheme is 'https'");
# HTTPS with bad hostname
$c = tcp_connect($https);