CIS 371 |
Simple Web Server |
Winter 2025 |
You may optionally complete this homework in teams of two. When you follow the link below, you will be given the option to either create a new team, or join an existing team.
GitHub Classroom URL:https://classroom.github.com/a/-zMjkgY8
This video demonstrates how to use GitHub Classroom with this assignment.
Objective
Learn the inner workings of a basic web server to better understand what underlies web platforms. In particular, students will observe the details of- interpreting an incoming request,
- identifying and finding the requested resource,
- preparing the proper response (which may be an error message), and
- delivering the content (which could be either text or binary data).
Details
Write a simple web server. You may (but are not required to) use my_http_server.py
as a starting point. (This
file is nearly identical to the code I walk through in this video.
You may use any language you like; you are not required to use Python.
Your web server must:
- Listen on port 8534 by default. (You can make this configurable, if you like; but, 8534 needs to be the default.)
- Correctly serve text, html, pdf, and images (gif, png, and jpeg). You may support additional types if you like.
- Your response headers must include
Content-Type
,Content-Length
, andConnection
.- You may assume the content type from the file's extension.
- You may hard-code the file extension to mime-type mapping.
- If there is no file extension, or if the file extension not recognized, use "
text/plain
"
- Return a 404 error when appropriate. (The response should also include a brief HTML message describing the problem.)
- If the requested document is a directory:
- Return
index.html
, if present (and ifindex.html
is a readable, regular file). - Otherwise, return a simple directory listing (with links). Important: Your link to
subdirectories must end with '
/
', otherwise, the web browser won't properly reset the base directory. (In other words, yourhref
needsImages/
not justImages
.)
- Return
- If the requested document is a directory and does not end with a
/
, return a 301 and redirect to a correctly formed URL. (For example, if the path is/Pictures
, redirect to/Pictures/
.)
Challenges
If you are looking for a challenge, try these. (These are just for fun. They are not required.)
- Make your server multi-threaded so that it can serve multiple requests at once.
- Implement an HTTPS server. Warning: I hear that getting the certificates set up correctly can be challenging. I've never done this; so, if you run into trouble, I'll be of limited help.
Rules
- You may work on this assignment in teams of at most two.
- You may use any language you like. Realize, however, that I will be of limited help if you choose something
other than Python or Java. (I know C, C++, and Ruby well; but, I don't know much about the particular networking
libraries.
I do not know any
.net
languages. I do not know Windows well.) - You may use standard socket and I/O libraries. You may not use any libraries that implement significant
web server functionality (e.g.,
com.sun.net.httpserver
). - Cite any sources you consult. Avoid ChatGPT and other sources that provide complete (or nearly complete) solutions.
- Every file should begin with a comment that includes the names of all team members.
- Follow good design practices. In particular, break your code into methods to avoid code duplication and to keep methods from getting too long.
Submission and Grading
If you use Python, this project will be partially auto-tested using GitHub Actions. Begin by using following this link to create a repository for this project. Once you have created your repository for this assignment, clone the repo to your local machine. Your repository will contain the following files:
my_http_server.py
- This is the example I covered in the video (plus a little bit of extra sample code you might find helpful). You don't have to use this file, or any of the code in it.
http_socket.py
- This is the socket "wrapper" used by the sample code. You are welcome to modify this if you like.
.github
- Configuration files for GitHub Actions. Don't mess with files here. (Attempting to modify the testing process to either (1) create a "false pass", or (2) examine the test cases is a serious violation of the CIS Academic Honesty Policy.)
studentData
- This directory contains files you can use to test your server.
testPlan.txt
- Complete this document to specify how you will test your server.
MyStaticWebServer.java
- This is the starter code for the Java version of the assignment. You are welcome to use it if you find it helpful.
Steps for completion and submission
- Begin by writing your test cases. Look through the requirements above, and write a short paragraph describing
how you will verify that your server meets each requirement. (
testPlan.txt
includes a couple samples.) - Write your code. Make sure your name appears in all files.
- If you are using Python for this assignment,
name your file
my_http_server.py
so the autograder can find it. (If you aren't using Python, I'll have to run the tests by hand.) - When your code passes all of your tests, push to the
main
branch. - Go to the
Actions
tab on the GitHub page for this project and launch the tests. - If your code fails my tests:
- Figure out what is missing from your test plan and add it.
- Fix your code
- Resubmit.
- When your code passes the GitHub tests, schedule a demo with me.
Hints and Reminders
- Remember to call
close
on your socket at the end of every call. Forgetting to close a socket may cause the next request to hang. - You must have a written test plan (described above).
- This project will not be graded until it passes all of my tests. Your grade is based primarily on when you get all the automated tests passing. (Code design and testing will also factor into your grade.)
- There are two stages to passing the tests.
- First, your code must pass the automated tests in GitHub
- Then, you must demonstrate your server to me and demonstrate that it can properly handle requests from a standard web browser
- Every file should include all team member names.
- If you are using Python, you might find these library functions helpful:
os.listdir()
os.path.isdir()
os.path.exists()
os.path.isfile()
os.access(index_path, os.R_OK)
Updated Monday, 10 February 2025, 12:09 PM
