✔️ Supports 5 common HTTP methods - GET, POST, PUT, DELETE and HEAD
✔️ Multithreaded
✔️ Configuration options
✔️ Level based logging support
✔️ Support for cookies
✔️ Automated basic testing
- Install all required packages using "pip3 install -r requirements.txt"
- Start the server using "python3 server.py port_no" , where port_no can be any valid port number. Not giving a port number will cause the server socket to bind to any available port. To bind to port numbers < 1024 prefixing the command with sudo is required.
- To stop or restart the server just type "stop" or "restart" into the terminal window where the server is running and press enter. A thread that continuously keeps waiting for input takes this input and stops/restarts the server.
- Server configuration options are available in the myserver.conf file in the conf directory.
- Access Log, Error Log and Post Data Logs are located in the log directory. If not already present the server will create them. (Being a general purpose web server, default behaviout for POST is to log POST data to PostDataLog.log)
Once the server has started, localhost:port_no can be accessed from the browser to access the sample default website hosted on the server.
Locate the file myserver.conf in the conf directory. The meanings of the various configuration options are as follows:
-
DocumentRoot : The folder where get requests are served from and where PUT requests store data. The value against this filed will indicate the location of the document root relative to the working directory of the project.
-
ErrorPages : Custom error pages can be put into this directory, error indicating status codes (Eg: 400, 404, etc) will be sent with body as pages put in this directory. If this directory does not contain status codes for some errors, a blank body will be sent for those.
-
MaxSimultaneousConnections : Maximum number of connections that can be handled at once, connections more than this will queue and if queue size is full no connection can be made. If set to 1, the server will essentially behave like a single threaded server.
-
QueueSize : The maximum number of connections that will be queued once maximum simultaenous connections have been reached
-
RequestTimeout : Timeout for requests. Since the server is capable of handling requests made line-by-line (telnet like fashion), this indicates the maximum amount of time the server will wait before terminating the connection once inactivity is detected. The timer resets after each line typed by the client, if request is being made line-by-line. This ensures the server isn't being kept hanging by a client who has initiated a connection but is taking too long to request.
-
ServerCloseTimeout : Timeout to wait for requests to complete once a "stop" is given. If all requests are served before this timeout, server will stop immediately. else it will wait for a maximum time specified here, if requests do not complete within this time, the server still closes the connection immediately. This takes care of hanging threads and sets a hard limit on the timeout that the server will wait for.
-
LogDir : Directory where log files are stored. (log by default)
-
ErrorLog : Name of the error log file name. (error.log by default)
-
AccessLog : Name of access log file name. (access.log by default)
-
PostDataLog : Name of file where log of POST data is stored. (postData.log by default)
-
Log Level : Only errors of severity equal to and above this level will be logged into error.log. Can be one of - CRITICAL, ERROR, WARNING, INFO, DEBUG, NOTSET (NOTSET by default)
Run "python3 multithreadTest.py n" using the terminal where n specifies the number of stress test threads. Individual stress tests will spawn n threads to test each method. Combination stress tests will spawn number of threads that approximately sum to n. Do not start the server beforehand, the testing program will itself start the server before starting testing.
Log Formats:
- Access Log :
<IpAddr-of-client> - - <date> <request-line> <response-status-code> <size-of-response-body-in-bytes> <referer> <user-agent> <value of set cookie header in response> <value of cookie header in request>
- Post Data Log :
<datetime> - <post_data_as_bytestring>