Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
T

toxy

> 前端框架
Open source

Hackable HTTP proxy for resiliency testing and simulated network conditions

2.7K stars0 likes4 views
WebsiteGitHub

About

Hackable HTTP proxy for resiliency testing and simulated network conditions

toxy

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.

Contents

  • Features
  • Introduction
    • Why toxy?
    • Concepts
    • How it works
  • Usage
    • Installation
    • Examples
  • Benchmark
  • Poisons
    • Poisoning scopes
    • Poisoning phases
    • Built-in poisons
      • Latency
      • Inject response
      • Bandwidth
      • Rate limit
      • Slow read
      • Slow open
      • Slow close
      • Throttle
      • Abort connection
      • Timeout
    • How to write poisons
  • Rules
    • Built-in rules
      • Probability
      • Time threshold
      • Method
      • Content Type
      • Headers
      • Response headers
      • Body
      • Response body
      • Response status
    • Third-party rules
    • How to write rules
  • Programmatic API
  • HTTP API
    • Usage
    • Authorization
    • API
    • Programmatic API
  • License

Features

  • Full-featured HTTP/S proxy (backed by rocky and http-proxy)
  • Hackable and elegant programmatic API (inspired on connect/express)
  • Admin HTTP API for external management and dynamic configuration
  • Featured built-in router with nested configuration
  • Hierarchical and composable poisoning with rule based filtering
  • Hierarchical middleware layer (both global and route scopes)
  • Easily augmentable via middleware (based on connect/express middleware)
  • Supports both incoming and outgoing traffic poisoning
  • Built-in poisons (bandwidth, error, abort, latency, slow read...)
  • Rule-based poisoning (probabilistic, HTTP method, headers, body...)
  • Supports third-party poisons and rules
  • Built-in balancer and traffic interceptor via middleware
  • Inherits API and features from rocky
  • Compatible with connect/express (and most of their middleware)
  • Able to run as standalone HTTP proxy

Introduction

Why toxy?

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.

Concepts

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.

How it works

…

Usage

Installation

bash
npm install toxy

Examples

See examples directory for more use cases.

…

Benchmark

See toxy/benchmark for details.

Poisons

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.

Poisoning scopes

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.

Poisoning phases

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.

Built-in poisons

Latency

Namelatency
Poisoning Phaseincoming / outgoing
Reaches the servertrue

Infects the HTTP flow injecting a latency jitter in the response

Arguments:

  • options object
    • jitter number - Jitter value in milliseconds
    • max number - Random jitter maximum value
    • min number - Random jitter minimum value
javascript
toxy.poison(toxy.poisons.latency({ jitter: 1000 }))
// Or alternatively using a random value
toxy.poison(toxy.poisons.latency({ max: 1000, min: 100 }))

Inject response

Nameinject
Poisoning Phaseincoming / outgoing
Reaches the serverfalse (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:

  • options object
    • code number - Response HTTP status code. Default 500
    • headers object - Optional headers to send
    • body mixed - Optional body data to send. It can be a buffer or string
    • encoding string - Body encoding. Default to utf8
javascript
toxy.poison(toxy.poisons.inject({
  code: 503,
  body: '{"error": "toxy injected error"}',
  headers: {'Content-Type': 'application/json'}
}))

Bandwidth

Namebandwidth
Poisoning Phaseincoming / outgoing
Reaches the servertrue

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:

  • options object
    • bytes number - Amount of chunk of bytes to send. Default 1024
    • threshold number - Packets time frame in milliseconds. Default 1000
javascript
toxy.poison(toxy.poisons.bandwidth({ bytes: 512 }))

Rate limit

NamerateLimit
Poisoning Phaseincoming / outgoing
Reaches the servertrue

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:

  • options object
    • limit number - Total amount of requests. Default to 10
    • threshold number - Limit time frame in milliseconds. Default to 1000
    • message string - Optional error message when limit is reached.
    • code number - HTTP status code when limit is reached. Default to 429.
javascript
toxy.poison(toxy.poisons.rateLimit({ limit: 5, threshold: 10 * 1000 }))

Slow read

NameslowRead
Poisoning Phaseincoming
Reaches the servertrue

Reads incoming payload data packets slowly. Only valid for non-GET request.

Arguments:

  • options object
    • chunk number - Packet chunk size in bytes. Default to 1024
    • threshold number - Limit threshold time frame in millisecon

Issues· 0 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

JavaScriptfailoverfailurehttp-proxynetwork

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 17, 2026
Category前端框架
PricingOpen source

> Related tools

R
React
用于构建用户界面的 JavaScript 库
V
Vue.js
渐进式 JavaScript 框架
N
Next.js
基于 React 的全栈 Web 框架