Docs
Reference for the decoy command line, the control API, Rules, Handlers and the Decoy CA. To answer your first call, start with Getting started. Decoy is part of SlopKit. The source is at https://gitlab.techtailors.net/slopkit/decoy.
This page describes decoy 0.1.0, built from the source at commit 3171d82. Decoy has no published release yet. Option names, defaults and output below were checked against that source and against a local build.
Decoy is one binary that is a DNS server and an HTTP(S) proxy. It answers third-party traffic, for example api.stripe.com, with Rules registered at runtime, and records every call in the Call Journal. The application is not changed.
Terms
- Intercepted Host
- A hostname whose DNS answers and HTTP(S) traffic Decoy takes over. Every other hostname resolves and connects normally.
- Rule
- A registered behavior that matches intercepted requests by host, path, method and headers, and decides the response: a fixed answer or a Handler.
- Handler
- The code part of a Rule. A Workers-style module that receives a request and returns a response.
- Rule Host
- A process, running in the JavaScript runtime you choose, where Handlers run with npm package support.
- Embedded Mode
- Running Handlers inside Decoy itself, with no external runtime and no npm packages.
- Unmatched Policy
- What Decoy does with an intercepted request that no Rule matches:
fail,passthroughordefault. Set per Intercepted Host. - Call Journal
- The record of every intercepted request and the response Decoy gave.
- Proxy Mode
- The client uses Decoy as an HTTP(S) proxy (
HTTPS_PROXY). Intercepted Hosts are answered by Decoy. Other hosts are tunnelled untouched. - Transparent Mode
- The client resolves an Intercepted Host through Decoy's DNS and connects straight to Decoy's TLS port. No proxy setting on the client.
- Decoy CA
- The certificate authority Decoy uses to answer HTTPS for Intercepted Hosts. Clients must trust it.
- Setup Helper
- A Decoy-provided way to point a client at Decoy and make it trust the Decoy CA:
decoy runanddecoy setup.
Command line
decoy [--state-dir DIR] <COMMAND>
decoy --version prints decoy 0.1.0. decoy <command> --help prints the options of one command.
| Command | What it does |
|---|---|
decoy serve | Runs Decoy. |
decoy ca export, decoy ca path, decoy ca bundle | Works with the Decoy CA. |
decoy run -- COMMAND... | Runs a command with the proxy and CA trust set up for Decoy. |
decoy setup browser, docker, kubernetes | Prints or writes configuration that points clients at Decoy. |
Global option
--state-dir DIR- Directory that holds the Decoy CA. Accepted by every command. Environment variable:
DECOY_STATE_DIR. Default:$DECOY_STATE_DIR, else$XDG_STATE_HOME/decoy, else~/.local/state/decoy. See State directory.
decoy serve
decoy serve [OPTIONS]
Starts the control API, the DNS server, the explicit proxy and the transparent TLS listener, then runs until interrupted with Ctrl-C. Each listener has a default address on 127.0.0.1. On start it prints the addresses it uses to stderr:
decoy: control API http://127.0.0.1:7411 decoy: DNS 127.0.0.1:5300 (udp+tcp), upstream 127.0.0.1:53 decoy: proxy http://127.0.0.1:7412 (HTTPS_PROXY / HTTP_PROXY) decoy: transparent tls://127.0.0.1:7413 decoy: CA <state-dir>/ca.pem
The upstream address in the DNS line is whatever resolver Decoy picked on your machine. A listener that is switched off is not printed. Log output uses the RUST_LOG filter and defaults to decoy=info.
Listeners
| Option | Environment variable | Default | Meaning |
|---|---|---|---|
--control-listen ADDR | DECOY_CONTROL_LISTEN | 127.0.0.1:7411 | Control API. Keep it on localhost: it can change what Decoy answers. |
--proxy-listen ADDR | DECOY_PROXY_LISTEN | 127.0.0.1:7412 | Explicit proxy (HTTP proxy and CONNECT). Use with HTTPS_PROXY. |
--tls-listen ADDR | DECOY_TLS_LISTEN | 127.0.0.1:7413 | Transparent TLS. Clients that resolve an Intercepted Host through Decoy's DNS connect here, and the SNI picks the host. Use port 443 where clients expect it. |
--dns-listen ADDR | DECOY_DNS_LISTEN | 127.0.0.1:5300 | DNS, UDP and TCP. |
--http-listen ADDR | DECOY_HTTP_LISTEN | off | Transparent plain HTTP, routed by the Host header. |
--no-dns | Switch off the DNS server. | ||
--no-proxy | Switch off the explicit proxy. | ||
--no-tls | Switch off the transparent TLS listener. |
ADDR is a socket address such as 127.0.0.1:7411.
DNS and passthrough
| Option | Environment variable | Default | Meaning |
|---|---|---|---|
--dns-answer IP | DECOY_DNS_ANSWER | 127.0.0.1 | Address Intercepted Hosts resolve to: an A record for IPv4, an AAAA record for IPv6. Repeatable, or comma-separated in the environment variable. |
--dns-ttl SECONDS | 1 | TTL of the DNS answers for Intercepted Hosts. | |
--upstream-dns ADDR | DECOY_UPSTREAM_DNS | first nameserver in /etc/resolv.conf that is not Decoy itself, else 1.1.1.1:53 | Resolver for every other name, and for reaching real hosts in passthrough. |
--upstream-ca FILE | none | Extra root certificate (PEM file) to trust when talking to real services. Repeatable. | |
--transparent-https-port PORT | 443 | Real port behind a transparent TLS connection (the passthrough target). | |
--transparent-http-port PORT | 80 | Real port behind a transparent HTTP connection (the passthrough target). | |
--upstream-timeout SECONDS | 30 | Time before connecting to or hearing from a real service times out. |
Bodies and the Call Journal
| Option | Default | Meaning |
|---|---|---|
--journal-capacity N | 10000 | Number of calls the Call Journal keeps. The oldest are dropped first. |
--max-body BYTES | 16777216 (16 MiB) | Largest request body accepted. Larger requests get 413 and are journaled. |
--journal-body BYTES | 1048576 (1 MiB) | Bytes of each body kept in the Call Journal. |
Handlers
| Option | Environment variable | Default | Meaning |
|---|---|---|---|
--rule-host COMMAND | DECOY_RULE_HOST | node | Command that starts the Rule Host's JavaScript runtime, for example node, bun or deno run -A. Split on whitespace. An empty value is refused. |
--handler-mode MODE | DECOY_HANDLER_MODE | host | Where Handlers run unless the Rule says otherwise: host (Rule Host) or embedded (Embedded Mode). |
Hosts at startup
--intercept HOST[=POLICY]- Registers an Intercepted Host when Decoy starts.
POLICYisfail,passthroughordefault. Without it the policy isfail. Repeatable. Any other policy value stops Decoy with an error. Hosts can also be added later through the control API.
decoy serve --intercept api.stripe.com --intercept '*.example.com=passthrough'
decoy ca
decoy ca export [-o FILE] decoy ca path decoy ca bundle
decoy ca export- Prints the Decoy CA certificate as PEM to stdout.
-o FILE(--out FILE) writes it to a file instead. Creates the CA on first use. decoy ca path- Prints the path of
ca.pemin the state directory. Creates the CA on first use. decoy ca bundle- Writes public roots plus the Decoy CA as one PEM bundle at
<state-dir>/ca-bundle.pemand prints its path to stdout. It prints the source of the public roots to stderr (decoy: public roots from <file>). Fails with a message if it finds no public roots. This is the file thatSSL_CERT_FILEmust point at.
A running Decoy also serves the CA at GET /ca and GET /ca.pem on the control API.
decoy run
decoy run [--proxy URL] [--control URL] -- COMMAND...
Starts COMMAND with the proxy and trust environment, replacing the decoy process. The exit code, signals and stdio are the command's own. COMMAND is required.
--proxy URL- Decoy's explicit proxy. Environment variable:
DECOY_PROXY. Default:http://127.0.0.1:7412. --control URL- Decoy's control API. The CA is read from it while it runs, and from the state directory otherwise. Environment variable:
DECOY_CONTROL. Default:http://127.0.0.1:7411.
Decoy prints a warning to stderr when nothing listens at the proxy address and starts the command anyway.
The command gets these environment variables:
| Variable | Value |
|---|---|
HTTPS_PROXY, HTTP_PROXY, https_proxy, http_proxy | The proxy URL. |
NO_PROXY, no_proxy | Your own value, plus localhost,127.0.0.1,::1. |
NODE_USE_ENV_PROXY | 1. Node 24 ignores HTTPS_PROXY for fetch without it. |
SSL_CERT_FILE, REQUESTS_CA_BUNDLE, CURL_CA_BUNDLE, GIT_SSL_CAINFO, AWS_CA_BUNDLE, PIP_CERT, CARGO_HTTP_CAINFO, NPM_CONFIG_CAFILE | The bundle: public roots plus the Decoy CA (<state-dir>/ca-bundle.pem, rewritten on every run). |
NODE_EXTRA_CA_CERTS, DENO_CERT | The Decoy CA alone (<state-dir>/client-ca.pem). These add to the client's own roots. |
The public roots come from the first of these that exists: SSL_CERT_FILE, NIX_SSL_CERT_FILE, /etc/ssl/certs/ca-certificates.crt, /etc/pki/tls/certs/ca-bundle.crt, /etc/ssl/ca-bundle.pem, /etc/pki/ca-trust/extracted/pem/tls-ca-bundle.pem, /etc/ssl/cert.pem, and a few more. If none exists, Decoy uses the platform trust store, and fails with a message if that has none.
SSL_CERT_FILE replaces the client's roots. That is why it names a bundle and not the Decoy CA alone: with the CA alone, every other HTTPS host fails.
decoy setup
All three subcommands read the CA from the running Decoy at --control and fall back to the state directory.
Shared options:
| Option | Environment variable | Default | Meaning |
|---|---|---|---|
--proxy URL | DECOY_PROXY | depends on the subcommand | Decoy's explicit proxy as the client will reach it. |
--control URL | DECOY_CONTROL | http://127.0.0.1:7411 | Decoy's control API. |
decoy setup browser
decoy setup browser [--format FORMAT]
Prints proxy and CA settings to stdout. The default --proxy is http://127.0.0.1:7412. It also writes <state-dir>/client-ca.pem.
--format FORMAT- One of
flags(default),agent-browseroragent-browser-env.
| Format | Output |
|---|---|
flags | Chromium flags: --proxy-server=<proxy>, --proxy-bypass-list=<-loopback> and --ignore-certificate-errors-spki-list=<base64 SHA-256 of the Decoy CA's public key>. |
agent-browser | --proxy <proxy> --ca-cert <path to client-ca.pem> |
agent-browser-env | AGENT_BROWSER_PROXY=<proxy> and AGENT_BROWSER_CA_CERT=<path to client-ca.pem>, one per line. |
With flags, Chromium accepts certificates that chain to the Decoy CA without the CA being installed in the NSS store. <-loopback> makes requests to localhost go through the proxy too: drop it to reach a local app directly. With flags, Decoy prints a note to stderr that other browsers need client-ca.pem imported. For Firefox or a system-wide install, import that file yourself.
decoy setup docker
decoy setup docker [--service NAME]... [--out DIR]
Writes ca.pem, ca-bundle.pem and compose.decoy.yaml into --out, and prints the docker compose command to run. The default --proxy is http://host.docker.internal:7412.
--service NAME- A Compose service to configure. Repeatable. Default:
app. --out DIR- Directory for the generated files. Default:
decoy-docker.
For each named service the override sets the same proxy and trust variables as decoy run, with the two files mounted read-only at /etc/decoy/ (ca.pem and ca-bundle.pem), and adds host.docker.internal:host-gateway to extra_hosts so the name resolves on Linux. Start Decoy with --proxy-listen 0.0.0.0:7412 so containers can reach it.
decoy setup kubernetes
decoy setup kubernetes [--namespace NAME] [--name PREFIX]
Prints two ConfigMaps as YAML to stdout, ready for kubectl apply -f -. The default --proxy is http://decoy.<namespace>.svc:7412.
--namespace NAME- Namespace of the ConfigMaps. Default:
default. --name PREFIX- Name prefix of the ConfigMaps. Default:
decoy.
The ConfigMap <PREFIX>-ca holds ca.pem and ca-bundle.pem. The ConfigMap <PREFIX>-env holds the variables, with file paths under /etc/decoy. The header comment of the output shows the envFrom and volume to add to a pod spec. Running Decoy in the cluster is up to your deployment: the proxy URL is the only link. A ConfigMap is limited to 1 MiB, and a bundle of public roots is about 200 KB.
State directory
The state directory holds the Decoy CA. It is the only state Decoy persists. Rules, hosts and the Call Journal live in memory and are gone when Decoy stops.
| File | Written by | Content |
|---|---|---|
ca.pem | first use of the CA | The Decoy CA certificate. |
ca-key.pem | first use of the CA | The CA private key, mode 0600. It never leaves this directory. |
ca-bundle.pem | decoy ca bundle, decoy run, decoy setup docker, decoy setup kubernetes | Public roots plus the Decoy CA. |
client-ca.pem | decoy run, decoy setup browser | A copy of the CA that clients are pointed at. It is not ca.pem, because the CA in use may belong to a Decoy with another state directory. |
rule-host.mjs | the first Handler request | The Rule Host script, compiled into the Decoy binary. |
The CA is generated on first use (ECDSA P-256, self-signed) and reloaded on every start, so an exported CA stays valid across restarts. Decoy mints a leaf certificate per SNI, only for Intercepted Hosts. Do not trust this CA outside test environments.
Reaching Decoy
- Proxy Mode
- Point the client at
--proxy-listen. Intercepted Hosts are answered by Decoy. Every other host is tunnelled to the real destination untouched. Plain HTTP requests andCONNECTare both accepted. - Transparent Mode
- Use Decoy as the client's resolver. Intercepted Hosts resolve to the
--dns-answeraddress, so the client connects to--tls-listen(or--http-listenfor plain HTTP). Everything else is forwarded to--upstream-dns. For Intercepted Hosts, other record types (AAAA when there is no IPv6 answer, HTTPS and SVCB) are answered empty, so clients cannot find the real address. Run Decoy with--tls-listen 0.0.0.0:443 --dns-listen 0.0.0.0:53, or forward the ports, and set--dns-answerto an address that clients can reach.
Trusting the Decoy CA
Clients must trust the Decoy CA for HTTPS to Intercepted Hosts. decoy run and the other Setup Helpers do this for the clients they cover. By hand:
| Client | Trust the CA with |
|---|---|
curl, OpenSSL, Python requests, Go, Ruby | SSL_CERT_FILE=$(decoy ca bundle), or REQUESTS_CA_BUNDLE or CURL_CA_BUNDLE. --cacert ca.pem works for a single call. |
| Node | NODE_EXTRA_CA_CERTS=<ca.pem>. With Node 24, also set NODE_USE_ENV_PROXY=1 so fetch honors HTTPS_PROXY. |
| Bun | NODE_EXTRA_CA_CERTS=<ca.pem> or SSL_CERT_FILE=<bundle>. |
| Java | Import the CA into a trust store with keytool -importcert. |
Rust reqwest with webpki-roots | Add the CA with add_root_certificate. This client ignores the environment. |
Clients that pin certificates, or ignore the system trust store, reject Decoy's certificates.
Control API
JSON over HTTP on --control-listen (default 127.0.0.1:7411). It can change what Decoy answers, and it has no authentication in this version: keep it on localhost, or inside the pod.
Errors are {"error": "..."} with one of these statuses:
| Status | Meaning |
|---|---|
400 | Malformed query, or DELETE /rules without a filter. |
404 | Unknown id or host. |
422 | A body that parses but is invalid, for example a Rule for a host that is not intercepted. |
501 | A Rule with a handler, on a Decoy with no Handler runtime. |
| Endpoint | Purpose |
|---|---|
GET /health | {"status":"ok"} |
GET /info | {"version": "...", "listeners": {...}}: the version and the addresses Decoy listens on. A listener that is off is null. |
GET /ca, GET /ca.pem | The Decoy CA certificate, PEM (application/x-pem-file). |
GET /hosts, POST /hosts | List or add Intercepted Hosts. |
GET /hosts/{name}, PUT /hosts/{name}, DELETE /hosts/{name} | Read, upsert or remove one. |
GET /rules, POST /rules, DELETE /rules | List, create or bulk delete Rules. |
GET /rules/{id}, DELETE /rules/{id} | Read or delete one Rule. |
GET /calls, DELETE /calls, GET /calls/{id} | Query or clear the Call Journal, or read one call. |
POST /reset | Delete every Rule and clear the Call Journal. Hosts stay. Answers {"rules_removed": n, "calls_removed": n}. |
Intercepted hosts
POST /hosts
{ "name": "api.stripe.com", "unmatched": "fail" }
name- Required. A host name, lowercased by Decoy.
*.example.comcovers every name belowexample.com, but notexample.comitself. IP addresses cannot be Intercepted Hosts. unmatched- Optional. The Unmatched Policy, as a shorthand string or an object. Default:
fail.
POST /hosts answers 201 with the host, or 200 when the host already existed and only its policy changed. PUT /hosts/{name} does the same with the name in the path and an optional {"unmatched": ...} body. GET /hosts answers {"hosts": [...]}.
DELETE /hosts/{name} removes the host and every Rule scoped to exactly that name, and answers {"removed": "<name>", "rules_removed": n}. DNS stops answering for it at once. Clients that cached the answer keep Decoy's address until the TTL (--dns-ttl, default 1 second) runs out.
Unmatched Policy
What Decoy does with an intercepted request that no Rule matches.
| Policy | Behavior |
|---|---|
{"policy":"fail"} | Answer 502 with a JSON body that names the host, method and path and says how to fix it. {"policy":"fail","status":501} picks another 4xx or 5xx status. |
{"policy":"passthrough"} | Forward the request to the real host and relay its answer. |
{"policy":"default","response":{...}} | Answer with the canned response, in the same shape as a Rule's respond. Without response: 200 with {}. |
The strings "fail", "passthrough" and "default" are accepted wherever a policy is.
Passthrough resolves the real address through --upstream-dns, never through Decoy's own DNS, so it cannot loop. In Proxy Mode it connects to the CONNECT target's port. In Transparent Mode it connects to --transparent-https-port or --transparent-http-port. It verifies the real service's certificate against the platform trust store plus any --upstream-ca files. If the real service is unreachable, the answer is a 502 whose body says why, and the Call Journal entry carries the same text in error.
Rules
POST /rules
{
"label": "scenario-42",
"host": "api.stripe.com",
"method": "POST",
"path": { "prefix": "/v1/payment_intents" },
"headers": [ { "name": "baggage", "contains": "scenario=42" } ],
"priority": 0,
"respond": {
"status": 402,
"headers": { "x-request-id": "req_123" },
"json": { "error": { "code": "card_declined" } },
"delay_ms": 150
}
}
The call answers 201 with the Rule, including id (r1, r2, and so on), created_at and hits. A JSON array of Rules creates all of them or none, and answers 201 {"rules": [...]}.
| Field | Meaning |
|---|---|
label | Free text. Groups Rules so they can be deleted together, for example one label per scenario. |
host | An Intercepted Host name or wildcard entry that is already registered, else 422. Omit it to match every Intercepted Host. |
method | One method or a list, case-insensitive. Omit for any. |
path | {"exact": "/a"}, {"prefix": "/a/"} or {"glob": "/a/*/b"}. It matches the path without the query. exact and prefix must start with /. A glob must start with / or *. Omit for any. |
headers | A list of conditions that must all hold. {"name": "x"} requires the header. equals compares the whole value. contains is a substring match, which suits baggage. Names are case-insensitive. |
priority | Integer. Default: 0. |
respond | The declarative answer. See below. |
handler | Code that computes the answer. See Handlers. |
Exactly one of respond and handler is required. A field that is not listed is refused with 422.
In a glob, * stays within one path segment, ** crosses segments and ? is one character within a segment.
Which Rule answers
Among all Rules that match, the highest priority wins. Among equals, the newest wins. A later Rule therefore overrides an earlier one without deleting it. Delete it, or its label, to go back.
respond
| Field | Meaning |
|---|---|
status | Default: 200. 1xx is refused. |
headers | Object of name to string, or to a list of strings for several values such as set-cookie. |
body | UTF-8 text. |
body_base64 | Binary body, base64. |
json | Any JSON value. Sent as the body, with content-type: application/json unless you set a content type. |
delay_ms | Milliseconds to wait before answering. |
At most one of body, body_base64 and json. Decoy adds x-decoy-outcome to every answer it gives, with the value rule, fail, passthrough or default. When a Rule answered, it also adds x-decoy-rule: <id>.
Listing and deleting
GET /ruleslists all Rules in creation order, as{"rules": [...]}. Filters:labelandhost.DELETE /rules/{id}deletes one Rule and answers{"removed": "<id>"}.DELETE /rules?label=scenario-42deletes every Rule with that label.host=...deletes those scoped to that host. Both together are combined with AND. The answer is{"removed": n}.DELETE /ruleswith no filter is refused with400.DELETE /rules?all=truedeletes every Rule.
Call Journal
Every intercepted request and the answer Decoy gave. Traffic that was only tunnelled, such as a CONNECT to a host that is not intercepted, is not journaled. The journal keeps the newest --journal-capacity calls.
GET /calls?host=api.stripe.com&header=baggage:scenario=42&since=2026-12-01T10:00:00Z
The answer is {"count": n, "calls": [...]}. Each call looks like this:
{
"id": "c17", "seq": 17,
"time": "2026-12-01T10:00:03.412Z",
"mode": "proxy", "scheme": "https",
"host": "api.stripe.com", "method": "POST",
"path": "/v1/payment_intents", "query": "expand=x",
"request": { "headers": { "baggage": "scenario=42" }, "body": "amount=100", "body_size": 10 },
"response": { "status": 402, "headers": { "content-type": "application/json", "x-decoy-rule": "r3" },
"body": "{\"error\":...}", "body_size": 41 },
"rule_id": "r3",
"outcome": "rule",
"duration_ms": 151
}
modeproxyfor explicit proxy traffic (CONNECT or absolute-form requests),transparentfor traffic that arrived through Decoy's DNS answer.host- The CONNECT target in Proxy Mode. The SNI in Transparent Mode, or the
Hostheader for plain HTTP. outcomerule, or the Unmatched Policy applied:fail,passthroughordefault.rule_idnullunless a Rule answered.error- Present when a passthrough or a Handler failed.
seq- Calls are numbered in arrival order, even when a slow call finishes after a later fast one.
Header names are lowercased, and repeated headers are joined with , . A body appears as body (UTF-8 text) or body_base64 (binary), plus body_size. When it was cut at --journal-body bytes, body_truncated is true.
Filters
GET /calls and DELETE /calls take these query parameters. All filters are combined with AND.
| Parameter | Meaning |
|---|---|
host, method | Match that host or method. |
path | Exact path. |
path_prefix | Path prefix. |
rule | Rule id. |
outcome | rule, fail, passthrough or default. |
header=name:substring | Request header contains the substring. Repeatable. header=name only requires the header. |
since | RFC 3339 timestamp or Unix milliseconds. |
after | A seq or an id such as c17. Returns only later calls: a cursor for what happened since you last looked. |
limit | Default 1000. The newest limit matches are returned, oldest first. GET only. |
bodies=false | Leave bodies out. GET only. |
GET /calls/{id} returns one call, by c17 or 17. DELETE /calls clears the journal, or only the calls that match the filters, and answers {"removed": n}.
Handlers
A Rule answered by code has a handler instead of respond:
POST /rules
{ "host": "api.stripe.com", "path": {"prefix": "/v1/"},
"handler": { "module": "handlers/stripe.ts", "env": { "decline": true }, "mode": "host" } }
module- Required. Path to the Handler file. A relative path is resolved from Decoy's working directory. The file must exist when the Rule is registered, else
422. Editing the file takes effect on the next request. env- Optional JSON object passed to the Handler.
mode- Optional.
hostorembedded. Default: the--handler-modeof the running Decoy.
A Handler is a Workers-style module with a default export:
import type { Handler } from "@slopkit/decoy";
export default {
async fetch(request, env) {
const order = await request.json();
return Response.json({ id: "pi_1", amount: order.amount }, { status: 402 });
},
} satisfies Handler;
request- A standard
Request. Its URL isscheme://host/path?queryas the client called it. env- The Rule's
handler.env, plusenv.decoy = { ruleId, host }.
A Handler that throws, returns something that is not a Response, or cannot be loaded makes Decoy answer 502. The Call Journal entry has outcome: "rule" and the message in error. A missing runtime command shows up the same way, with a message that starts starting Rule Host. Handler answers are journaled like any other.
Rule Host
The default mode. Decoy starts the Rule Host in the runtime from --rule-host on the first Handler request, and restarts it if it dies. Handlers run in that runtime, so npm imports work. They resolve from the Handler file's location. TypeScript runs as is on Node 24 (type stripping), Bun and Deno. A Handler that does not answer within 30 seconds fails with 502.
The host script is packages/decoy/host.mjs in the source. It is compiled into the Decoy binary and written to <state-dir>/rule-host.mjs. The protocol is JSON-RPC 2.0 over the host's stdin and stdout, one JSON object per line, version 0.1. protocolVersion is major.minor: both sides refuse to talk when the major versions differ. Decoy calls these methods:
| Method | Params | Result |
|---|---|---|
initialize | { protocolVersion } | { protocolVersion, runtime } |
handler.load | { module } | null. Imports the module and checks its default export. |
handler.fetch | { module, env, request } | { status, headers: [[name, value]], bodyBase64 } |
shutdown | null | null, then the host exits. |
request is { ruleId, host, url, method, headers: [[name, value]], bodyBase64 }. Bodies are buffered. The host's stderr is passed through, and the host sends console.log to stderr.
Embedded Mode
--handler-mode embedded, or "mode": "embedded" on a Rule, runs the Handler inside Decoy. swc strips the TypeScript and QuickJS runs the JavaScript. No Node, Bun or Deno is needed. The same source runs in either mode as long as it stays inside these limits.
A Handler is compiled when its Rule is registered: a syntax error or an unsupported import is refused with 422. Each request runs in a fresh QuickJS runtime, so Handlers share no state.
Supported:
- TypeScript syntax: types, interfaces,
satisfies,as, generics andimport type. Enums, namespaces and parameter properties also compile here, but Node's type stripping rejects them, so avoid them if the Handler must also run in a Rule Host on Node. export default { fetch(request, env) }, sync or async, returning aResponse.- Imports of
@slopkit/decoy(defineHandler) and of relative files, such as./lib/util.ts. Imports used only as types are dropped. - Globals:
Request,Response(includingResponse.jsonandResponse.redirect),Headers,URL,URLSearchParams,TextEncoder,TextDecoder,atob,btoa,structuredClone(a JSON round trip),crypto.randomUUIDandcrypto.getRandomValues(not secure, meant for test ids), andconsole(to Decoy's stderr), plus what QuickJS provides. - Bodies as strings, bytes or
URLSearchParams, andrequest.text(),json(),arrayBuffer()andbytes().
Not supported:
- npm packages and
node:imports. They are refused with a message that names the specifier. fetch, timers such assetTimeout, streams,FormData,Blobandcrypto.subtle. A Handler that waits on a timer fails with "never finished". Usedelay_msin a declarative Rule, or run the Handler in a Rule Host.- More than 10 seconds of run time or 128 MiB of memory.
Errors answer 502 and appear in the Call Journal's error, as in the Rule Host.
@slopkit/decoy package
@slopkit/decoy 0.1.0 holds the Handler types and the Rule Host script. It is in packages/decoy in the source, and this reference does not cover an install from a registry. It exports:
Handler- Interface with
fetch(request: Request, env: Env): Response | Promise<Response>. Env{ decoy: { ruleId: string; host: string }; [key: string]: unknown }.defineHandler(handler)- Returns its argument. It only gives editors the types. Nothing needs importing at run time.
PROTOCOL_VERSION- The Rule Host protocol version the package speaks:
"0.1".
Limits
- Bodies are buffered. There is no streaming or SSE through Decoy.
- Only HTTP(S) is intercepted. There is no SMTP STARTTLS or raw TCP, and clients that connect by IP address are not intercepted.
- Clients that pin certificates, or ignore the system trust store, reject Decoy's certificates.
- Rules, hosts and the Call Journal live in memory. Only the CA persists.
- The control API has no authentication.
Related
- Getting started: https://decoy.slopkit.dev/start/
- Product home: https://decoy.slopkit.dev/
- Source, including the vocabulary in
CONTEXT.md, the control API notes indocs/api.mdand the decisions indocs/adr/: https://gitlab.techtailors.net/slopkit/decoy - The SlopKit family: https://slopkit.dev