CS-2910 Network Protocols

Dr. Mark Sebern -- Fall quarter 2014-2015

Lab 4: Simple Python HTTP server

Revised: 9 October 2014

Lab assignment

This is a team assignment; each team should be two members unless a different size is approved by the instructor.


The goal of this lab is to write a short Python program, to respond to HTTP requests and return web resources, acting as an HTTP server.


  1. Download the skeleton Python template: cs2910-lab-httpserver-template-py.txt
  2. Rename the template file to cs2910-lab04-username1-username2{-username3}.py, where each "usernameN" is the MSOE email username (e.g., "smithj") of a team member, in alphabetical order.
  3. Edit the header of the file to include your team members' names, in the format provided. (Note: the header format has changed from prior labs.)
  4. Complete the handle_request method to parse a request and respond by returning the designated resource. You will want to add other helper methods, but do not change the any other code provided in the template.
    • Note that this method will be invoked on a separate thread for each request received. This means that there may be multiple copies of this method running simultaneously, if the web client opens more than one connection at a time (e.g., to download resources that are referenced in a main HTML file).
    • For this reason, you should not rely on any global variables, but instead pass data as arguments to related functions. Each thread will have its own execution stack.
  5. Add comments at the end of your Python file, with the following information:
    • A description of the functionality you implemented and the results of your testing.
    • Comments on your experience in completing the lab, including any problems you encountered. Briefly explain what you learned.
    • Questions and suggestions.

You may not use a prebuilt library like Lib/BaseHTTPServer; the point of this lab is for you to understand the low-level implementation of the HTTP protocol.

You may and should use the utility functions that are included near the end of the skeleton template file. Read the description for each function and ask the instructor if you have questions about them.

Additional implementation details will be discussed in class. If you have questions about these requirements, ask in class or lab.

If this base functionality turns out to be too easy, you may experiment with adding additional functions, but be sure the basic requirements are still met.

Try to divide up the primary responsibility for parts of the program in an equitable way.

Assignment details

Relative URL File path, relative to the directory with your Python server code file File to serve (right-click to download)
/ (default) ./index.html index.html
index.html ./index.html index.html
sebern1.jpg ./sebern1.jpg sebern1.jpg
style.css ./style.css style.css
e-sebern2.gif ./e-sebern2.gif e-sebern2.gif

Hints and Notes

Submission (Due Tuesday, 10/14/2014, 9PM)

One team member should submit your Python file by uploading to the CS-2910-031 Submissions folder on box.msoe.edu. If you have questions about this process, consult the instructor well in advance of the submission deadline.

Please follow these submission instructions exactly, including details of the filename, or your submission may be rejected, resulting in a "F" grade.