Created
January 22, 2010 18:02
-
-
Save nihen/283983 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/lib/HTTP/Server/PSGI.pm b/lib/HTTP/Server/PSGI.pm | |
index 64c4099..5895efc 100644 | |
--- a/lib/HTTP/Server/PSGI.pm | |
+++ b/lib/HTTP/Server/PSGI.pm | |
@@ -42,8 +42,16 @@ sub new { | |
server_ready => $args{server_ready} || sub {}, | |
max_workers => $args{max_workers} || 1, | |
max_reqs_per_child => $args{max_reqs_per_child} || 100, | |
+ ssl => exists $args{ssl} ? 1 : 0, | |
+ ssl_key_file => $args{ssl_key_file} || 'certs/server-key.pem', | |
+ ssl_cert_file => $args{ssl_cert_file} || 'certs/server-cert.pem', | |
+ socket_class => exists $args{ssl} ? 'IO::Socket::SSL' : 'IO::Socket::INET', | |
}, $class; | |
+ if ($self->{ssl}) { | |
+ require IO::Socket::SSL; | |
+ } | |
+ | |
if ($self->{max_workers} > 1) { | |
try { | |
require Parallel::Prefork; | |
@@ -75,12 +83,16 @@ sub run { | |
sub setup_listener { | |
my $self = shift; | |
- $self->{listen_sock} ||= IO::Socket::INET->new( | |
+ $self->{listen_sock} ||= $self->{socket_class}->new( | |
Listen => SOMAXCONN, | |
LocalPort => $self->{port}, | |
LocalAddr => $self->{host}, | |
Proto => 'tcp', | |
ReuseAddr => 1, | |
+ $self->{ssl} ? ( | |
+ SSL_key_file => $self->{ssl_key_file}, | |
+ SSL_cert_file => $self->{ssl_cert_file}, | |
+ ) : (), | |
) or die "failed to listen to port $self->{port}:$!"; | |
$self->{server_ready}->($self); | |
@@ -127,7 +139,7 @@ sub accept_loop { | |
REMOTE_ADDR => $conn->peerhost, | |
'psgi.version' => [ 1, 1 ], | |
'psgi.errors' => *STDERR, | |
- 'psgi.url_scheme' => 'http', | |
+ 'psgi.url_scheme' => $self->{ssl} ? 'https' : 'http', | |
'psgi.run_once' => Plack::Util::FALSE, | |
'psgi.multithread' => Plack::Util::FALSE, | |
'psgi.multiprocess' => $self->{prefork}, |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment