myHTTP server is a HTTP/1.1 compliant web server which handles common web requests.
This project implements a simple multithreaded HTTP/1.1 compliant web server designed to handle various HTTP requests (GET, POST, PUT, DELETE, etc.), manage cookies, support multipart form data, and handle basic logging and error management. This server was built to explore the inner workings of the HTTP protocol, server design, and request handling, and is based on the HTTP/1.1 RFC 2616.
-
HTTP Methods Implementation
- Supports core HTTP methods including
GET,POST,PUT,DELETE,HEAD.
- Supports core HTTP methods including
-
Multipart Form Data Handling
- Ability to process multipart form data for file uploads and form submissions.
-
Logging
- Implements access logs and error logs to track request details and server issues.
-
Customized Configuration File
- Allows server configuration through a user-friendly
.conffile.
- Allows server configuration through a user-friendly
-
Cookies
- Support for setting and retrieving cookies between the client and server for session management.
-
Access Logs
- Provides detailed logs of all incoming requests, including IP address, request time, and response status.
-
Error Logs
- Detailed logging of any errors, including error types and affected resources.
To start the server, use the following command:
bash start.shTo stop the server, use the following command:
bash stop.shTo test the server, you can use the testing.py script, which will do regression testing
python testing.pyThe config file contains the server’s configuration settings. Below is the format of the configuration file:
[DOCUMENTROOT]
DocumentRoot = httpfiles/
[POSTROOT]
PostRoot = POST/
[PUTROOT]
PutRoot = PUT/
[PIDFILE]
pidfile = pid.txt
[TIMEOUT]
TimeOut = 300
[KEEP_ALIVE]
KeepAlive = Off
[MAX_KEEP_ALIVE_REQUESTS]
MaxKeepAliveRequests = 5
[KEEP_ALIVE_TIMEOUT]
KeepAliveTimeout = 20
[ACCESSLOG]
AccessLog = logs/access.log
[ERRORLOG]
ErrorLog = logs/error.log
[MAX_SIMULTANEOUS_CONNECTION]
MaxSimultaneousConnection = 5
[PORT_NUMBER]
PortNumber = 12001
The server maintains an access log for all incoming requests. This log helps monitor server activity and understand client interactions. Below is an example of an access log entry:
127.0.0.1:50126 - [Sun, 14 Nov 2021 17:23:09 GMT] “GET / HTTP/1.1” 200 3148 python-requests/2.22.0- Client IP Address:
127.0.0.1indicates the source of the request. - Port:
50126is the port number used by the client. - Timestamp:
[Sun, 14 Nov 2021 17:23:09 GMT]records the date and time of the request. - Request Method and URI:
"GET / HTTP/1.1"shows the HTTP method (GET) and the requested resource (/). - Status Code:
200indicates the request was successful. - Response Size:
3148bytes were sent to the client. - User-Agent:
python-requests/2.22.0shows the client application making the request.
The server logs errors encountered while processing client requests. Error logs help identify and debug issues with the server or incoming requests. Below is an example of an error log entry:
127.0.0.1:50128 - [Sun, 14 Nov 2021 17:23:09 GMT] “GET /index23.html HTTP/1.1” 404 Not Found python-requests/2.22.0 Client-Error:4xx- Client IP Address:
127.0.0.1indicates the source of the request. - Port:
50128is the port number used by the client. - Timestamp:
[Sun, 14 Nov 2021 17:23:09 GMT]records the date and time of the request. - Request Method and URI:
"GET /index23.html HTTP/1.1"shows the HTTP method (GET) and the requested resource (/index23.html). - Status Code and Description:
404 Not Foundindicates the requested resource could not be found on the server. - User-Agent:
python-requests/2.22.0shows the client application making the request. - Error Type:
Client-Error:4xxindicates the error type, in this case, a client-side error.
- Access Log:
logs/access.log - Error Log:
logs/error.log
These log files are specified in the config file and can be customized based on your requirements.
This project would not have been possible without the following resources and contributions:
- MDN Web Docs: For comprehensive documentation on HTTP and web technologies.
- RFC 2616: The foundational standard for HTTP/1.1 protocol implementation.
