bcarroll has asked for the wisdom of the Perl Monks concerning the following question:

I am building a web server based on the HTTP::Daemon::SSL module. While testing I noticed that sending a request via http:// causes the server to die without any indication as to why.
#simple HTTPS web server. (must have a ./certs directory with server-k +ey.pem and server-cert.pem or server won't start) use HTTP::Daemon::SSL; my $d = HTTP::Daemon::SSL->new(LocalPort => '443') || die $!; print "HTTPS server running at: ", $d->url, "\n"; while (my $c = $d->accept) { while (my $r = $c->get_request) { $c->send_file_response('./index.html'); } $c->close; undef($c); }
...And my test index.html page
<html> <body> TEST </body> </html>
Requesting https://localhost in a web browser works fine, but if I request http://localhost:443 the perl script dies. Any ideas? ...I am running ActiveState Perl 5.10 on Windows XP

Replies are listed 'Best First'.
Re: HTTP::Daemon::SSL based server dieing when http is requested
by zwon (Abbot) on Jan 05, 2009 at 23:27 UTC

    From documentation:

    The accept() method will return when a connection from a client is available. In a scalar context the returned value will be a reference to a object of the HTTP::Daemon::ClientConn::SSL class which is another IO::Socket::SSL subclass.
    So if connection isn't SSL accept returns udef as HTTP::Daemon::ClientConn::SSL object wasn't created and your loop stops.

    Update: this works:

    while () { my $c = $d->accept or next; while ( my $r = $c->get_request ) { $c->send_file_response('./index.html'); } $c->close; undef($c); }