Hackable HTTP proxy for resiliency testing and simulated network conditions
Hackable HTTP proxy for resiliency testing and simulated network conditions
Not actively maintained, may not work with latest node.js runtimes. If you are interested in maintaining toxy, please open an issue.
Hackable HTTP proxy to simulate server failure scenarios, systems resiliency testing and unexpected network conditions, built for node.js.
It was mainly designed for failure resistance testing, when toxy becomes particularly useful in order to cover fault tolerance and resiliency capabilities of a system, especially in disruption-tolerant networks and service-oriented architectures, where toxy may act as MitM proxy among services in order to inject failure.
toxy allows you to plug in poisons, optionally filtered by rules, which essentially can intercept and alter the HTTP flow as you need, performing multiple evil actions in the middle of that process, such as limiting the bandwidth, delaying network packets, injecting network jitter latency or replying with a custom error or status code. It primarily operates at L7, although it can simulate L3 network conditions.
toxy can be fluently used programmatically or via HTTP API. It was built on top of rocky, a full-featured middleware-oriented HTTP proxy, and it's also pluggable in connect/express as standard middleware.
Requires node.js +4.
There're some other similar solutions like toxy in the market, but most of them do not provide a proper programmatic control and usually are not easy to hack, configure or are directly closed to extensibility.
Furthermore, the majority of those solutions only operates at TCP L3 level stack instead of providing high-level abstractions to cover common requirements in the specific domain and nature of the HTTP L7 protocol, like toxy tries to provide
toxy brings a powerful hackable and extensible solution with a convenient abstraction, but without losing a proper low-level interface capabilities to deal with HTTP protocol primitives easily.
toxy was designed based on the rules of composition, simplicity and extensibility. Via its built-in hierarchical domain specific middleware layer you can easily augment toxy features to your own needs.
toxy introduces two directives: poisons and rules.
Poisons are the specific logic which infects an incoming or outgoing HTTP transaction (e.g: injecting a latency, replying with an error). One HTTP transaction can be poisoned by one or multiple poisons, and those poisons can be also configured to infect both global or route level traffic.
Rules are a kind of match validation filters that inspects an HTTP request/response in order to determine, given a certain rules, if the HTTP transaction should be poisoned or not (e.g: if headers matches, query params, method, body...). Rules can be reused and applied to both incoming and outgoing traffic flows, including different scopes: global, route or poison level.
…npm install toxySee examples directory for more use cases.
…See toxy/benchmark for details.
Poisons host specific logic which intercepts and mutates, wraps, modify and/or cancel an HTTP transaction in the proxy server. Poisons can be applied to incoming or outgoing, or even both traffic flows (see poison phases).
Poisons can be composed and reused for different HTTP scenarios. They are executed in FIFO order and asynchronously.
toxy has a hierarchical design based on two different scopes: global and route.
Global scope points to all the incoming HTTP traffic received by the proxy server, regardless of the HTTP method or path.
Route scope points to any incoming traffic which matches with a specific HTTP verb and URI path.
Poisons can be plugged to both scopes, meaning you can operate with better accuracy and restrict the scope of the poisoning,
for instance, you might wanna apply a bandwidth limit poisoning only to
a certain routes, such as /download or /images.
See routes.js for a featured example.
Poisons can be plugged to incoming or outgoing traffic flows, or even both.
Incoming poisoning is applied when the traffic has been received by proxy but it has not been forwarded to the target server yet.
Outgoing poisoning refers to the traffic that has been forwarded to the target server and when proxy receives the response from it, but that response has not been sent to the client yet.
This means, essentially, that you can plug in your poisons to infect the HTTP traffic before or after the request is forwarded to the target HTTP server or sent to the client.
This allows you apply a better and more accurated poisoning based on the request or server response.
For instance, given the nature of some poisons, like inject error,
you may want to enable it according to the target server response (e.g: some header is present or not).
See poison-phases.js for a featured example.
| Name | latency |
| Poisoning Phase | incoming / outgoing |
| Reaches the server | true |
Infects the HTTP flow injecting a latency jitter in the response
Arguments:
objectnumber - Jitter value in millisecondsnumber - Random jitter maximum valuenumber - Random jitter minimum valuetoxy.poison(toxy.poisons.latency({ jitter: 1000 }))
// Or alternatively using a random value
toxy.poison(toxy.poisons.latency({ max: 1000, min: 100 }))| Name | inject |
| Poisoning Phase | incoming / outgoing |
| Reaches the server | false (only as incoming poison) |
Injects a custom response, intercepting the request before sending it to the target server. Useful to inject errors originated in the server.
Arguments:
objectnumber - Response HTTP status code. Default 500object - Optional headers to sendmixed - Optional body data to send. It can be a buffer or stringstring - Body encoding. Default to utf8toxy.poison(toxy.poisons.inject({
code: 503,
body: '{"error": "toxy injected error"}',
headers: {'Content-Type': 'application/json'}
}))| Name | bandwidth |
| Poisoning Phase | incoming / outgoing |
| Reaches the server | true |
Limits the amount of bytes sent over the network in outgoing HTTP traffic for a specific time frame.
This poison is basically an alias to throttle.
Arguments:
objectnumber - Amount of chunk of bytes to send. Default 1024number - Packets time frame in milliseconds. Default 1000toxy.poison(toxy.poisons.bandwidth({ bytes: 512 }))| Name | rateLimit |
| Poisoning Phase | incoming / outgoing |
| Reaches the server | true |
Limits the amount of requests received by the proxy in a specific threshold time frame. Designed to test API limits. Exposes typical X-RateLimit-* headers.
Note that this is very simple rate limit implementation, indeed limits are stored in-memory, therefore are completely volatile. There're a bunch of featured and consistent rate limiter implementations in npm that you can plug in as poison. You might be also interested in token bucket algorithm.
Arguments:
objectnumber - Total amount of requests. Default to 10number - Limit time frame in milliseconds. Default to 1000string - Optional error message when limit is reached.number - HTTP status code when limit is reached. Default to 429.toxy.poison(toxy.poisons.rateLimit({ limit: 5, threshold: 10 * 1000 }))| Name | slowRead |
| Poisoning Phase | incoming |
| Reaches the server | true |
Reads incoming payload data packets slowly. Only valid for non-GET request.
Arguments:
objectnumber - Packet chunk size in bytes. Default to 1024number - Limit threshold time frame in milliseconNo open issues yet, or sync has not completed.