Assignment_HTTP_Library
Assignment_HTTP_Library
Objective
The objective of this assignment is to understand the basics of HTTP and socket programming by
creating a simple HTTP server in Python. The server will handle HTTP GET requests and serve static
HTML content.
Requirements
1. Create a Python class SimpleHTTPServer.
Instructions
1. Setting Up the Server:
4. Error Handling:
1. Respond with a 405 Method Not Allowed status for unsupported HTTP
methods.
5. Multi-threading:
Python
import socket
import threading
import os
import logging
class SimpleHTTPServer:
def __init__(self, host='127.0.0.1', port=8080):
self.host = host
self.port = port
# TODO: Initialize server socket
# TODO: Bind socket to host and port
# TODO: Start listening for connections
# Set up logging
logging.basicConfig(filename='server.log', level=logging.INFO,
format='%(asctime)s - %(message)s')
def start(self):
# TODO: Accept incoming connections and handle each client in a
new thread
pass
if __name__ == "__main__":
server = SimpleHTTPServer()
server.start()
Tasks
1. Initialize the Server:
1. Implement the handle_client method to read the request from the client
socket.
5. Multi-threading:
1. Ensure that the server can handle multiple clients simultaneously using
threading.
Submission
Submit the following:
2. A README file explaining how to run the server and test it using a web browser or an
HTTP client tool like curl or Postman.
Bonus
1. Serve Static Files:
1. Extend the server to serve static files (e.g., HTML, CSS, JS) from a directory.
2. Logging:
Evaluation Criteria
• Correct implementation of the server initialization and socket setup.
This assignment should help students understand the fundamentals of HTTP and socket
programming while giving them hands-on experience in creating a simple HTTP server.