Skip to main content
httpmon lets you write JavaScript scripts that intercept and modify HTTP traffic in real time. You can add headers, block requests, mock responses, set breakpoints, and more. Scripts live in ~/.httpmon/scripts/. Each script is a .js file with YAML frontmatter in comments followed by JavaScript hook functions.

Script format

A script has two parts: a YAML frontmatter block (wrapped in // --- comment delimiters) and one or both hook functions.

Frontmatter fields

Hooks

onRequest(ctx) runs before the request is sent to the server. onResponse(ctx) runs before the response reaches the client.

Script manager

Press S in the TUI to open the script manager. From there you can toggle, create, and delete scripts. Scripts are reloaded each time the manager opens. Scripts are tagged with category badges — Script, Map Local, or Breakpoint — based on which APIs they use (ctx.respondWith() for Map Local, ctx.breakpoint() for Breakpoint).
httpmon script manager

Examples

All examples below use httpbin.org so you can test them immediately.
Add custom headers to outgoing requests. The httpbin /headers endpoint echoes back all received headers, so you can verify the script works.
Override the status code or headers on a response before it reaches the client.
Block all requests to slow endpoints. Blocked requests never leave the proxy.
Return a synthetic JSON response without hitting the server. Use ctx.respondWith() to define the status, body, and headers.
Serve a file from disk instead of forwarding the request. The file path is relative to the script directory (~/.httpmon/scripts/).
Pause the request flow and open an interactive editor. You can inspect and modify the request before it is sent to the server.
Inject a bearer token into requests. The httpbin /bearer endpoint validates the Authorization header and returns 200 on success or 401 without it.
Rewrite the URL to redirect a request to a different endpoint. The client sees the response from the new URL.

URL matching

The match field accepts an array of glob patterns. Use * as a wildcard for any sequence of characters. You can specify multiple patterns to match different endpoints with a single script:

Error handling

If a script throws an error, httpmon catches it and continues processing the request normally. The error is tracked and displayed in the script manager next to the script name, so you can spot and fix issues without disrupting traffic.
See the Script API reference for the full list of context fields and methods.