Shriram Krishnamurthi <shriram@cs.rice.edu> wrote:
+---------------
| rpw3@rigden.engr.sgi.com (Rob Warnock) writes:
| > Obligatory Scheme content: If your Scheme provides a socket library,
| > see how small an HTTP server you can write entirely in Scheme!
|
| Indeed (and look out for more from us on this in the future):
| ; A functional Web server written in PLT Scheme.
| [...code deleted...]
+---------------
Wow, very nice! I was actually thinking of something a lot simpler
[albeit a lot less useful], more along the lines of the sample code
in the SIOD distribution ("http-server.scm"), which only serves up a
computed "page" out of the program itself. You can do that in MzScheme
in less than 1/3 the size of your example.
But your code serves up *files*, and handles MIME types, too! More
interestingly, since it uses MzScheme's builtin threads, it leaves
the top-level REPL alive while it's serving requests. [Hmmm... And
it looks look like it wouldn't be very hard to make each request run
in a separate thread, either.]
Of course, there are a lot of "exercises for the student" left to do
(little things like reading the whole request header *before* going off
to serve the page [so you can check for cookies and/or authentication],
or handling POST requests, or serving each request in it's own thread,
timing out stalled connections or clients, etc.), but it's actually
somewhat useful just as it stands.
-Rob
-----
Rob Warnock, 41L-955 rpw3@sgi.com
Applied Networking http://reality.sgi.com/rpw3/
Silicon Graphics, Inc. Phone: 650-933-1673
1600 Amphitheatre Pkwy. PP-ASEL-IA
Mountain View, CA 94043