|
| 1 | +[](https://github.com/your-org/chaos-proxy-go/actions) |
| 2 | +[](https://github.com/your-org/chaos-proxy-go) |
| 3 | + |
| 4 | +# chaos-proxy-go |
| 5 | + |
| 6 | +**chaos-proxy-go** is a Go port of [fetch-kit/chaos-proxy](https://github.com/fetch-kit/chaos-proxy): a proxy server for injecting configurable network chaos (latency, failures, connection drops, rate-limiting, etc.) into any HTTP or HTTPS traffic. Use it via CLI or programmatically to apply ordered middleware (global and per-route) and forward requests to your target server, preserving method, path, headers, query, and body. |
| 7 | + |
| 8 | +--- |
| 9 | + |
| 10 | +## Features |
| 11 | + |
| 12 | +- Simple configuration via a single `chaos.yaml` file |
| 13 | +- Programmatic API and CLI usage |
| 14 | +- Built-in middleware primitives: latency, latencyRange, fail, failRandomly, failNth, dropConnection, rateLimit, cors, throttle, bodyTransform |
| 15 | +- Extensible registry for custom middleware |
| 16 | +- Supports both request and response interception/modification |
| 17 | +- Method+path route support (e.g., `GET /api/users`) |
| 18 | +- Robust short-circuiting: middlewares halt further processing when sending a response or dropping a connection |
| 19 | + |
| 20 | +--- |
| 21 | + |
| 22 | +## Installation |
| 23 | + |
| 24 | +Download the latest release from [GitHub Releases](https://github.com/your-org/chaos-proxy-go/releases) or build from source: |
| 25 | + |
| 26 | +```sh |
| 27 | +go build -o chaos-proxy-go . |
| 28 | +``` |
| 29 | + |
| 30 | +--- |
| 31 | + |
| 32 | +## Usage |
| 33 | + |
| 34 | +### CLI |
| 35 | + |
| 36 | +```sh |
| 37 | +./chaos-proxy-go --config chaos.yaml [--verbose] |
| 38 | +``` |
| 39 | +- `--config <path>`: YAML config file (default `./chaos.yaml`) |
| 40 | +- `--verbose`: print loaded middlewares and request logs |
| 41 | + |
| 42 | +### Programmatic API |
| 43 | + |
| 44 | +```go |
| 45 | +import "your-org/chaos-proxy-go/internal/proxy" |
| 46 | + |
| 47 | +// Load config and start server |
| 48 | +cfg := config.Load("chaos.yaml") |
| 49 | +server := proxy.New(cfg, false) |
| 50 | +server.Start() |
| 51 | +// ... |
| 52 | +``` |
| 53 | + |
| 54 | +--- |
| 55 | + |
| 56 | +## Configuration (`chaos.yaml`) |
| 57 | + |
| 58 | +See the [original chaos-proxy README](https://github.com/fetch-kit/chaos-proxy) for detailed config options. This Go port supports a compatible YAML structure. |
| 59 | + |
| 60 | +--- |
| 61 | + |
| 62 | +## Middleware Primitives |
| 63 | + |
| 64 | +- `latency(ms)` — delay every request |
| 65 | +- `latencyRange(minMs, maxMs)` — random delay |
| 66 | +- `fail({ status, body })` — always fail |
| 67 | +- `failRandomly({ rate, status, body })` — fail with probability |
| 68 | +- `failNth({ n, status, body })` — fail every nth request |
| 69 | +- `dropConnection({ prob })` — randomly drop connection |
| 70 | +- `rateLimit({ limit, windowMs, key })` — rate limiting (by IP, header, or custom) |
| 71 | +- `cors({ origin, methods, headers })` — enable and configure CORS headers |
| 72 | +- `throttle({ rate, chunkSize, burst, key })` — throttles bandwidth per request |
| 73 | +- `bodyTransform({ transform })` — parse and mutate request body with a custom function |
| 74 | + |
| 75 | +--- |
| 76 | + |
| 77 | +## Extensibility |
| 78 | + |
| 79 | +Register custom middleware in Go. See the `internal/middleware` package for examples. |
| 80 | + |
| 81 | +--- |
| 82 | + |
| 83 | +## Security & Limitations |
| 84 | + |
| 85 | +- Proxy forwards all headers; be careful with sensitive tokens. |
| 86 | +- Intended for local/dev/test only. |
| 87 | +- HTTPS pass-through requires TLS termination; not supported out-of-the-box. |
| 88 | +- Not intended for stress testing; connection limits apply. |
| 89 | + |
| 90 | +--- |
| 91 | + |
| 92 | +## License |
| 93 | + |
| 94 | +MIT |
| 95 | + |
| 96 | +--- |
| 97 | + |
| 98 | +> This is a Go port of [fetch-kit/chaos-proxy](https://github.com/fetch-kit/chaos-proxy). |
0 commit comments