Coder Social home page Coder Social logo

hrishikeshathalye / myserver Goto Github PK

View Code? Open in Web Editor NEW
2.0 2.0 1.0 1.72 MB

A multithreaded HTTP/1.1 Server

HTML 8.29% CSS 19.45% JavaScript 11.57% SCSS 28.08% Python 32.60%
http http-server python3 python computer-networks computer-network network networking web server

myserver's Introduction

MyServer

๐ŸŒ

A minimal, multithreaded HTTP/1.1 compliant Webserver

License: MIT made-with-python Version

Table of Contents

๐ŸŽฏ Features

โœ”๏ธ Supports 5 common HTTP methods - GET, POST, PUT, DELETE and HEAD
โœ”๏ธ Multithreaded
โœ”๏ธ Configuration options
โœ”๏ธ Level based logging support
โœ”๏ธ Support for cookies
โœ”๏ธ Automated basic testing

๐ŸŽฏ Installation And Usage

  1. Install all required packages using "pip3 install -r requirements.txt"
  2. 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.
  3. 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.
  4. Server configuration options are available in the myserver.conf file in the conf directory.
  5. 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.

๐ŸŽฏ Config

Locate the file myserver.conf in the conf directory. The meanings of the various configuration options are as follows:

  1. 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.

  2. 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.

  3. 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.

  4. QueueSize : The maximum number of connections that will be queued once maximum simultaenous connections have been reached

  5. 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.

  6. 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.

  7. LogDir : Directory where log files are stored. (log by default)

  8. ErrorLog : Name of the error log file name. (error.log by default)

  9. AccessLog : Name of access log file name. (access.log by default)

  10. PostDataLog : Name of file where log of POST data is stored. (postData.log by default)

  11. 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)

๐ŸŽฏ Testing

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.

๐ŸŽฏ Logs

Log Formats:

  1. 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>
  1. Post Data Log :
<datetime> - <post_data_as_bytestring>

๐ŸŽฏ Acknowledgements

myserver's People

Contributors

hrishikeshathalye avatar shaunak27 avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

Forkers

ajayinnovative2

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.