Git Product home page Git Product logo

http-server-fault-emulator's Introduction

http-server-fault-emulator

HTTP server to emulate faults (close TCP connection, timeout etc) ##Overview This is small utility to emulate HTTP server failures that happens when an HTTP server is overloaded or faulty. The goal is to use this utility to reproduce responses that cannot be produced using a utility that is based on a conventional HTTP server like Gin.

A client uses the utility instead of real server could experience various issues:

  • Closed connection - after establishing the TCP connection (there could be some delay) the server closes the TCP connection
  • Empty response - after establishing the TCP connection (there could be some delay) the server sends end of HTTP packet closes the TCP connection
  • Return any binary response (sample stored in file) and closes the connection, to emulate interrupted process of data transmission.

How to use

To start the server run go run main.go. The configuration file config.yaml is in the root of the project directory. The config file can be edited while server is running and changes to all properties (except the emulationport property, change to this property requires restarting the service) are applied on fly.

The server behaviour to request to any path on the service is configured in the behavior section of the config file. Currently only one behaviour is supported, but as it covers my needs it is good enough.

The following configuration

{
 behaviour: configurable_response,
 emulationport: "9000",
 configurable_response: {
     delay_before_millisec: 2000,
 }
}

starts server listening to connections on port 9000. The active behaviour is configurable_response that is configured after accepting a connection to wait for 2 sec and close the connection.

The following configuration

{
 behaviour: configurable_response,
 emulationport: "9000",
 configurable_response: {
     delay_before_millisec: 100,
     response_file: "response_sample2.txt",
     delay_after_millisec: 200,
 }
}

starts server listening to connections on port 9000. The active behaviour is configurable_response that is configured to delay after accpting a connection for 100 milliseconds, then read content for the response_sample2.txt file in binary mode and send it via socket, then sleep for another 200 milliseconds and close the connection. As it was mentioned, the config could be changed, for example, modifying the delays or using another file and the changes will be applied to the next request to the service. The file is not cached, so any modification in the file also applied in the next request to the service.

TODO

  • to update the response that was loaded from file replacing by template some values, like current date and time
  • to support different behaviours\behaviour params for different paths
  • to log what exactly happens for the request

http-server-fault-emulator's People

Contributors

alex-korobko avatar

Watchers

 avatar

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.