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

Documentation for the Simple HTTP server in under 100 lines

by Corion (Patriarch)
on Oct 04, 2001 at 21:16 UTC ( [id://116771]=note: print w/replies, xml ) Need Help??


in reply to Simple HTTP in under 100 lines

The objective was to write a simple HTTP server that supported resuming of downloads via the Range heeaders. The server should also be fairly secure, as it runs unattended on my firewall box, and thus, it should also not require any fancy setup that could be misconfigured.

The server must be run with the taint option of Perl for even more security. I toyed with the idea of locking the server in a chroot() jail, but getting Perl/HTTP::Daemon to work in such a jail is no easy feat, so I ditched the idea (see objective above).

The server works under both, Win32 and Unix, but under Win32 it dosen't support fork, as the fork emulation is not always working for me. In the spirit of simplicity, it also dosen't support any CGI capabilities, since CGI capabilities present a security hole waiting to be exploited. Also, "hidden" files starting with a dot (".") are not available for download as well. On the upside, the server fully supports persistent connections.

Of course, the total number of lines is arbitrarily set at 99 lines, as there is much whitespace to be compressed, but I wanted to keep a sensible mix of obfuscation/compression and readability, as I think that maybe other people than me would want to use this code.

Command line options

perl -wT miniserver.pl [document_root]

Disclaimer

Even though I tried to be as paranoid as possible about my own code, I can't guarantee that the code is secure in any way other than taking up valuable CPU time and/or disk space. If you find any interesting exploits, please add them in a reply here, so others can learn from my mistakes.

2001-10-05 Update: Fixed small germanism thanks to John M. Dlugosz

2001-10-05 Update: Fixed missing use strict; at the top of the script. Thanks to ybiC for mentioning it to me. My Pascal upbringing seems to have protected me against violating strict, as no code rework was necessary...

2004-07-11 Update: Fixed _stamp routine so it actually displays a useful timestamp. Thanks to BrowserUK for finding it in that code.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://116771]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (6)
As of 2024-04-19 11:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found