- To create a HTTP-based web server that handles multiple simultaneous requests from users.
- In this Assignment we are expected to learn basic of TCP socket Programming.
- We are expected to learn the HTTP protocol including various HTTP errors.
- We are also expected to learn socket threading and handle simultaneous requests using threading.
- Python 2.7
- Document Directory:
www - Configuration file:
ws.conf
- The server first reads configuration parameters from
ws.conffile. - The file contains derivateives such as server ip, port number and content-types
- If there is an error in the file then the server will start while returning
HTTP 500 Internal serverfor all requests
- Server handles simultaneous requests using multi-threading.
- The main
server functioncreate a new thread withhandlerfunction. - The handler function then receives data from client, checks the request and then returns httpresponse
- If the handler function receives an
Connection: Keep-Alivedirective, it will set socket timeout and wait for more data. - If no data was received in the timeout period or the last packet did not have a
Connection: Keep-Alivederivateiv then the handler function will close the socket and kill the thread.
- Server will first check for the method directive
- if the method is not (GET,OPTIONS,HEAD,POST,PUT,DELETE,TRACE) it will return
Invalid method error
- if the method is not (GET,OPTIONS,HEAD,POST,PUT,DELETE,TRACE) it will return
- Server will next check the path of request file
- if the path does not start with
/, server will returnInvalid URL error
- if the path does not start with
- Server will next check for the
HTTPversion- if the verion is not
HTTP/1.1orHTTP/1.0, server will returnInvalid HTTP-Verion error
- if the verion is not
- If the server can not find the requested file in
DocumentRootdirectory, it will return a404 not founderror
- If the method in request header is not present in
RequestMethodSupportparamter of configuration file then server will return501 not implementederror
- If there is an error in server configuration file, such as no value specified for content-type or no port specified then server will return a
500 internal server error
python2.7 webServer.py (echo -en "GET /index.html HTTP/2.1\r\nHost: localhost\r\n\n"; sleep 10) | telnet 127.0.0.1 8080 (echo -en "GRT /index.html HTTP/1.1\r\nHost: localhost\r\n\n"; sleep 10) | telnet 127.0.0.1 8080 (echo -en "GET /index.html HTTP/1.1\r\nHost: localhost\r\n\n"; sleep 10) | telnet 127.0.0.1 8080 (echo -en "POST /index.html HTTP/1.1\r\nHost: localhost\r\n\n"; sleep 10) | telnet 127.0.0.1 8080