Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer

HTTP::Server::Simple forking/SSL/IPv6

by cavac (Deacon)
on Oct 24, 2011 at 13:28 UTC ( #933399=perlmeditation: print w/replies, xml ) Need Help??

This isn't so much a question as it is an informal article for the record, since the question seems to pop up from time to time... but i'll take any advice for making a better version.
HTTP::Server::Simple (or HSS for short) and its ::CGI companion are quite handy. In fact so handy, i'm using it in my Maplat project. The questions that pop up from time seem to revolve around three topics:
  • How do i make HSS a forking/preforking webserver?
  • How do i implement HTTPS (=HTTP+SSL)?
  • Is there *any* way to implement IPv6 in HSS?

I've been pondering about exactly these issues for quite a while, something like two years in fact. HSS is quite extendable, but it involves overloading an "online patching". While it's certainly possible to do it, for a novice it's quite difficult or even impossible to get it right.
I therefore proudly present HTTP::Server::Simple::CGI::PreFork. While you still have to read a lot of documentation (and annotate mine...), it does the overloading and patching for you. It seems to run quite stable, but looking at the code is only for the faint of heart (mostly code quality issues, i'm afraid).
It fixes the three main questions above, namely it has:
  • Preforking option (Single threaded by default for debugging)
  • SSL support (throws a lot of warning, though)
  • IPv6 support when the correct Net::Server version is installed
Except for the additional options, it should work as a plugin replacement for HTTP::Server::Simple::CGI.
Note: If you want to run SSL and Non-SSL, you have to start two instances of your server.
Any comments, patches and fixed POD is very welcome!
Don't use '#ff0000':
use Acme::AutoColor; my $redcolor = RED();
All colors subject to change without notice.

Replies are listed 'Best First'.
Re: HTTP::Server::Simple forking/SSL/IPv6
by Anonymous Monk on Oct 24, 2011 at 13:37 UTC
    How does it compare with the various Plack servers?

      To be absolutely honest: I have no idea.

      I started to develop a small in-house webservice with HTTP::Server::Simple::CGI and it grew over time to a big, mission critical central service. Since i started, i extended HSSC. A few days ago, at a request from a friend, i pulled the relevant code from Maplat and put it into it's own module.

      With HSSC it's somehow like a marriage. It's quite easy to start, but very time consuming and expensive to get rid of. And while it lasts, you get in trouble very quickly if you are unfaithful to your selected partner. So, no, i never took the time to compare with other frameworks.

      I can only say this for performance and stability: I'm running a webservice with about 50 users and like cyclic 300-500 automated clients without any troubles on a midrange linux server. And it only ever fails on me when i don't test my updates. Other than that, HSSC(P) runs quite smoothly.

      Don't use '#ff0000':
      use Acme::AutoColor; my $redcolor = RED();
      All colors subject to change without notice.

        Moving from HTTP::Server::Simple to a PSGI setup using Plack shouldn't be hard. In HTTP::Server::Simple(::CGI), you have the subroutine handle_request, which prints its output. In PSGI, you have an anonymous subroutine that returns the HTML to be sent.

        This is the part you need to change, instead of printing your HTML, you return a triplet of [ $status, $headers, $body ].

Re: HTTP::Server::Simple forking/SSL/IPv6
by dwalin (Monk) on Oct 25, 2011 at 07:43 UTC
    HTTP::Server::Simple integrates nicely with Net::Server which provides forking and preforking behaviors. I think it is mentioned in the docs for HSS, too.


      Yes, that's what my module does.

      "Integrates nicely" is not a 100% true, though. While it easy enough to use Net::Server with HSS, there are some pitfalls, though. Like, you have to disable the two calls to "binmode" in the _process_request() sub when (and only when) using SSL.

      So, HSSCP is not "revolutionary", "ultimate" or "the best"; rather i took all the workarounds and steps-to-make-it-work i had come up with and put them into a more or less easy-to-use module. With the hope that this module now makes it easier for beginners to set up a preforking all-perl webserver.

      For more complex tasks, there are a lot of frameworks around like Catalyst or the ("cavac has still not released 1.0 and working examples") Maplat server.

      Don't use '#ff0000':
      use Acme::AutoColor; my $redcolor = RED();
      All colors subject to change without notice.

        Um. I'm not sure it's such a great idea after all. I mean, HSS is awesome for prototyping but after several months of extensive testing I'm much less inclined to put it in production, preforking or not. Anyway, it's easy enough to setup reverse proxy scenario with a bona fide HTTP server even for prototyping, so what's the reason for adding SSL and stuff?

        Besides, Plack is the way to go these days. It's not an ideal solution but it's near enough so the only reason for avoiding it I see is compatibility to Perl versions older than 5.8. YMMV though.


Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlmeditation [id://933399]
Approved by Corion
Front-paged by Arunbear
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (6)
As of 2017-06-23 05:28 GMT
Find Nodes?
    Voting Booth?
    How many monitors do you use while coding?

    Results (535 votes). Check out past polls.