Recently at work, we needed to setup a dummy HTTPS server just as an endpoint that needed to do... something. Nothing specific. Just something that did SSL/TLS and returned a 200 response. Immediately I thought of python's builtin SimpleHTTPServer, which can be used to serve the current directory:
$ python -m SimpleHTTPServer Serving HTTP on 0.0.0.0 port 8000 ...
And away it goes. But to put SSL into it, more code is needed, but there are examples around.
I wondered how easily (or not) I could do it with Perl and a Plack server.
First, I needed the following dependencies installed:
- Plack::App::Directory. This comes with the standard Plack distribution, but it's used to serve a directory listing.
- Starman. This is currently the only Plack server that supports SSL, without requiring something like nginx in front of it. A little disappointing, but not a big deal.
- IO::Socket::SSL. To do the SSL stuff. Requires OpenSSL.
These can either be managed by Carton, or you can just install them with cpanm.
$ cpanm Plack Starman IO::Socket::SSL
Next, I need to generate a dummy SSL certificate.
$ openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout server.key -out server.crt
Now I can run the server:
$ plackup -s Starman --listen :8000 \ --enable-ssl --ssl-cert server.crt --ssl-key server.key \ -MPlack::App::Directory -e'Plack::App::Directory->new(root=>".")' 2017/08/29-12:27:01 Starman::Server (type Net::Server::PreFork) starting! pid(38015) Resolved [*]:8000 to [0.0.0.0]:8000, IPv4 Binding to SSL port 8000 on host 0.0.0.0 with IPv4 Setting gid to "20 20 20 504 401 12 61 79 80 81 98 33 100 204 395 398 399" Starman: Accepting connections at https://*:8000/
... and the directory listing is available via https://locahost:8000/
It's not as simple as Python's SimpleHTTPServer to get going, but it works!
No comments:
Post a Comment