On Wed Jun 26 09:08:20 2013, ARISTOTLE wrote:
Show quoted text> There should to instruct the Plack handler to set up an SSL-based
> port, from the command line.
>
> In particular, it should be possible to have both a plain port and an
> SSL-based port.
Done.
--
Paul Evans
=== modified file 'lib/Plack/Handler/Net/Async/HTTP/Server.pm'
--- lib/Plack/Handler/Net/Async/HTTP/Server.pm 2013-12-30 02:43:38 +0000
+++ lib/Plack/Handler/Net/Async/HTTP/Server.pm 2014-03-26 18:13:00 +0000
@@ -39,6 +39,14 @@
This is internally implemented using L<Net::Async::HTTP::Server::PSGI>;
further information on environment etc.. is documented there.
+If L<IO::Async::SSL> is available, this handler supports accepting connections
+via C<https>
+
+ plackup -s Net::Async::HTTP::Server --ssl ...
+
+Any other options whose names start C<ssl_> will be passed on to the SSL
+listen method.
+
=cut
=head1 METHODS
@@ -94,6 +102,10 @@
map { $_ => delete $opts{$_} } qw( listen server_ready socket queuesize ),
}, $class;
+ # Grab all of the SSL options
+ $self->{ssl} = 1 if exists $opts{ssl}; delete $opts{ssl};
+ $self->{$_} = delete $opts{$_} for grep m/^ssl_/, keys %opts;
+
keys %opts and die "Unrecognised keys " . join( ", ", sort keys %opts );
return $self;
@@ -138,27 +150,39 @@
else {
my ( $host, $service ) = $listen =~ m/^(.*):(.*?)$/;
+ my %SSL_args;
+ if( $self->{ssl} ) {
+ require IO::Async::SSL;
+ %SSL_args = (
+ extensions => [qw( SSL )],
+ );
+
+ foreach my $key ( grep m/^ssl_/, keys %$self ) {
+ my $val = $self->{$key};
+ # IO::Async::Listener extension wants uppercase "SSL"
+ $key =~ s/^ssl/SSL/;
+
+ $SSL_args{$key} = $val;
+ };
+ }
+
$httpserver->listen(
host => $host,
service => $service,
socktype => "stream",
queuesize => $queuesize,
+ %SSL_args,
+
on_notifier => sub {
$self->{server_ready}->( {
host => $host,
port => $service,
+ proto => $self->{ssl} ? "https" : "http",
server_software => ref $self,
} ) if $self->{server_ready};
},
-
- on_resolve_error => sub {
- die "Cannot resolve - $_[-1]\n";
- },
- on_listen_error => sub {
- die "Cannot listen - $_[-1]\n";
- },
- );
+ )->get;
}
}