Computer Science Canada

Smallest (source code) webserver I've seen so far - REBOL

Author:  btiffin [ Fri Apr 04, 2008 5:45 am ]
Post subject:  Smallest (source code) webserver I've seen so far - REBOL

rebol []
secure[net allow library throw shell throw file throw %. [allow read]]p: open/lines tcp://:80 forever[attempt[s: length? b: read/binary to-file next pick parse pick c: p/1 1 none 2 write-io c b: rejoin[#{}"HTTP/1.0 200 OK^M^JServer: Rebol^M^JContent-length: "s"^M^JContent-type: text/html^M^J^M^J"b]length? b close c]]

317 bytes of source to serve files out of the current directory. 308 if you skip the rebol [] header and paste the one line to the console. For when it absolutely, positively has to be there overnight.

I've posted this Cal Dixon script before, but this one comes with a question;

Any examples of shorter sources that safely deliver files out of a working directory?

You might get close using Python's SimpleHTTPServer on a BaseHTTPServer, and I'd be curious to see.


Author:  jernst [ Fri Apr 04, 2008 7:38 am ]
Post subject:  Re: Smallest (source code) webserver I've seen so far - REBOL

Just wondering what the point of having a small amount of source is, shouldn't you compare something more useful such as the memory footprint or the bytes of final compiled code.

Author:  btiffin [ Fri Apr 04, 2008 3:58 pm ]
Post subject:  Re: Smallest (source code) webserver I've seen so far - REBOL

In general, not much perhaps. But in this case; I have this script stashed away for those rare times when I need to share a file with a colleague. A one-line webserver is a functionally useful "toy". Less source code means a great deal in grokking. Less is more when the brain can take it in one quick glance. Other metrics are important yes, but the humanity of programming cannot be dismissed. imho. When I was young I had an 8 or 9 digit brain (remember 9 things and recall them). Now in my 40's I'm down to 7 digits and I have to split 10 digit dialing into 3 distinct memory packets of npa-nnx-local. I can remember a 4 line script far longer and with better recall than a two page masterpiece.

Well, plus ... it's nerdy. Love nerdy. Smile


Author:  haskell [ Fri Apr 04, 2008 4:00 pm ]
Post subject:  RE:Smallest (source code) webserver I\'ve seen so far - REBOL

Hacks are fun. It's why the obfuscation contests are so popular and why people love to toy with esoteric programming languages. It's a fun hobby.