Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow SSL when used under Server::Starter #147

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions lib/Starman/Server.pm
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,39 @@ sub run {
);
}

# When used under server_starter this is called from
# Net::Server::SS::PreFork->pre_bind
sub maybe_upgrade_to_ssl {
my ($self, $sock, $ssl_this_port) = @_;

# $options->{ssl} is from starman's --enable-ssl
my $wants_ssl = $self->{options}{ssl} || $ssl_this_port;
return unless $wants_ssl;

require Net::Server::Proto::SSL;

bless($sock, 'Net::Server::Proto::SSL');

my $options = $self->{options};

$sock->configure_SSL({
$options->{ssl_cert} ? (SSL_cert_file => $options->{ssl_cert}) : (),
$options->{ssl_key} ? (SSL_key_file => $options->{ssl_key}) : (),

# For list of net_server_args, see Net::Server::Proto::SSL's @ssl_args.
# To pass them to starman use e.g. --net_server_SSL_cipher_list
$options->{net_server_args} ? %{ $options->{net_server_args} } : (),

# Newer versions of Net::Server >= 2.011 need this to postpone the SSL
# handshake. Older versions ignore it and don't need it.
SSL_startHandshake => 0,

SSL_server => 1,
});

$sock->NS_proto('SSL');
}

sub pre_loop_hook {
my $self = shift;

Expand Down