fileserveHTTP.ss: Serve your local files over HTTP
The GNU GPL source of the first release, Version 0.8 is available at http://bitbucket.org/amitksaha/foobar-scripts/src/tip/fileserveHTTP.ss
I accidentally came across the SimpleHTTPServer.py Python module, while back and immediately found it a very useful utility script. As part of my Scheme learning exercise, I implemented the same (AFAIK, complete) functionality in the Scheme language using PLT Scheme.
More: Systems Programming with PLT Scheme helped me get started with a multi-threaded server (till Step 6). From then on, I tried to understand what the code in the Python module does, and tried to implement the functionality in the Scheme code.
High Level Execution flow
The code execution starts from (serve) procedure which creates the server process and hence is ready for accepting new client connections. A new client connection is handled in a new thread. For the first GET request, the list of current sub-directories and files in the directory from which the server was started is returned (in a HTML page) to the client. This is performed by the (doGet-list) procedure. After the first request, the new GET requests are served by the (doGet-file) procedure.
- I have used a lot of plt-scheme APIs, so this code will work only with plt-scheme
- I have developed this code on Ubuntu Linux and that is the only OS, on which I know it works. Specifically, I would like to test the path name handling and MIME type detection on other Unix and may be Windows too
- The code doesn’t do any exception handling as of now
- This is my first proper Scheme program, so I might have written C/Java/Python in Scheme.
Usage instruction can be found in the source code itself. Please suggest comments/suggestions for improvements to firstname.lastname@example.org or post a comment here.