Net-Async-HTTP-Server
view release on metacpan or search on metacpan
lib/Plack/Handler/Net/Async/HTTP/Server.pm view on Meta::CPAN
}
=head1 METHODS
=cut
=head2 run
$handler->run( $psgi_app );
Creates the HTTP-listening socket or sockets, and runs the given PSGI
application for received requests.
=cut
sub run
{
my $self = shift;
my ( $app ) = @_;
my $loop = IO::Async::Loop->new;
my $queuesize = $self->{queuesize} || 10;
foreach my $listen ( @{ $self->{listen} } ) {
my $httpserver = Net::Async::HTTP::Server::PSGI->new(
app => $app,
);
$loop->add( $httpserver );
# IPv6 addresses contain colons. They'll be wrapped in [] brackets
my $host;
my $path;
if( $listen =~ s/^\[([0-9a-f:]+)\]://i ) {
$host = $1;
}
elsif( $listen =~ s/^([^:]+?):// ) {
$host = $1;
}
elsif( $listen =~ s/^:// ) {
# OK
}
else {
$path = $listen;
}
if( defined $path ) {
require IO::Socket::UNIX;
unlink $path if -e $path;
my $socket = IO::Socket::UNIX->new(
Local => $path,
Listen => $queuesize,
) or die "Cannot listen on $path - $!";
$httpserver->configure( handle => $socket );
}
else {
my ( $service, $ssl ) = split m/:/, $listen;
$ssl ||= $self->{ssl};
my %SSL_args;
if( $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 => $ssl ? "https" : "http",
server_software => ref $self,
} ) if $self->{server_ready};
},
)->get;
}
}
$loop->run;
}
=head1 SEE ALSO
=over 4
=item *
L<Net::Async::HTTP::Server> - serve HTTP with L<IO::Async>
=item *
L<Plack> - Perl Superglue for Web frameworks and Web Servers (PSGI toolkit)
=back
=head1 AUTHOR
Paul Evans <leonerd@leonerd.org.uk>
=cut
( run in 1.080 second using v1.01-cache-2.11-cpan-71847e10f99 )