Answered step by step
Verified Expert Solution
Question
1 Approved Answer
There is no code handout and the implementation should be done in python. You must implement a web server that is capable of serving files
There is no code handout and the implementation should be done in python.
You must implement a web server that is capable of serving files from a lo- a cal folder. This means that you are only required to implement the HTTP GET method, but you may want to implement the HEAD method as well, as it may be useful for testing. The server should be able to run indefinately, by which it is meant that it should not just process a given number of response and then stop. The server should work as a plain file server and should accept a path to a folder and a port number. The server may also take an address to listen on, but if this is not implemented, the server should listen on all addresses on the port specified. Files and folders in specified path should be served up by the webserver. If a folder on the server is accessed (with a URL ending in a /) then you should serve up the contents of file named index.html, if one exists, or a listing of the files and folders, if index.html does not exist. When a request is received, it should be parsed and verified as a valid HTTP request. The URL from the request is then mapped to the underlying file sys- tem. If the requested file does not exist, the server responds with error code 404 and a short message, otherwise the file contents are returned. You will need to use other error codes as appropriate. Your server should be resilient, and so malformed messages should not cause it to crash and prevent it recieving future messages. In general you should familiarize yourself with HTTP RFC (RFC 2616), which explains how the protocol is supposed to be interpreted. Be aware that the HTTP protocol is very large, and you should by no means attempt to support all fea- tures. For instance, there are 40 different HTTP headers, some of which go far out of scope for this assignment. You should implement support for at least 3 different Request headers, as well as all necessary Response headers. It is up to you to select which headers and additional features to implement, but as a min- imum you should always support those that are required by the protocol e.g. a 'Hos header is required to be part of any HTTP Request so should always be supported, however an 'Accept-Encoding' header is optional and so it up to you if you implement or not. If you are in doubt, please use the Discord to ask for clarifications, but try to read the RFC before asking questions. The features you implement should be implemented in such a way to be standards compliant. You should also ensure that your server is standards com- pliant even given the features you do not implement. As an example, you do probably not want to implement persistent connections, but you must send the appropriate header to your clients indicating that you do not do so. Your web server should be implemented in Python. Your implementation MUST use socket programming, meaning that the use of an HTTP aware library is not allowed. You can use other libraries, e.g., text parser, regular expressions, url parser, etc. It is sufficient if your server can only serve a single request at a time (i.e. you do not need to implement multithreading)Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started