Skip to content

r00tdaemon/ServesUp

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Simserve

Simserve is a server simulator which can be used to simulate server interactions of a program. It is highly configurable as users can configure it to produce valid http responses for given set of requests.

Files

  • config_parse.py - Parse the config.json file using the Config class. Also, creates the request handlers to be used by the server.

  • handler.py - Defines a custom request handler which can be configured to send different responses based on the options given to it and logs each request-response pair.

  • server.py - Main file to start the server.

  • plugins.base - The base plugin class used to for dynamic responses. More on this below.

Installation and Usage

This tool is written in python 3.6
Clone the repository.

git clone https://github.com/ujjwal96/simserve.git
cd simserve

To install dependencies run -
pip install -r requirements.txt

To configure the tool copy conf.json.example to conf.json.

  • port - Specifies the port on which to run the server.
  • routes - List of paths for which server responds.
    • path - Each route has a path string to define the URL path.
    • responses - List of responses for each route for different methods. If no response is defined for a method server returns 405 status.
      • headers - Dictionary of headers to send with the response.
      • body - The response body for given route. Used if "response_type is "static"
      • methods - HTTP methods for which this response should be sent.
      • response_type - How to generate the response. Can be "static" or "script"
      • script - Name of python module from which to generate the response. Used if "response_type is "script". User can provide either a default plugin(customresp), a relative path to python script or an absolute path to the script.

To run - simserve
By default it looks for config file in current working dir. To specify path to config file pass -c flag.
simserve -c <path to conf.json>

Plugins

Users can create their own plugins which will allow them to generate dynamic responses based on the requests received.

To create a plugin you need to import the base plugin class and override its abstract method.

from simserve.plugins.base import Plugin

class MyResponse(Plugin):
    def response(self, request):
        return f"Hello from plugin"

The customresp.py serves as a simple example of a plugin.

Future Improvements

  • Option to log request and responses to a file.
  • Create a GUI for the tool.

About

Simulate server interactions of a program

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages