Skip to main content
Scripts are JavaScript files stored in ~/.httpmon/scripts/. Each script has YAML frontmatter inside JS comments and exports onRequest and/or onResponse hooks.

Script file format

The frontmatter is delimited by // --- lines. Each YAML line is prefixed with // .

Frontmatter fields

onRequest(ctx)

Runs before the request is sent upstream.

onResponse(ctx)

Runs before the response reaches the client.

ctx.respondWith(options)

Short-circuits the normal proxy flow and returns a synthetic response. Available in both onRequest and onResponse. In onRequest, calling respondWith stops script execution immediately. The request is never sent upstream. In onResponse, execution continues after the call. When you use file, the content-type is auto-detected from the file extension. The file and body options are mutually exclusive.

ctx.breakpoint()

Pauses the flow for interactive editing in the TUI. You can inspect and modify headers and body before the flow continues.

ctx.readFile(path)

Reads a file from disk and returns its contents as a string. Returns null if the file does not exist. Paths are resolved relative to the script’s directory.

URL match patterns

Match patterns use glob syntax with * wildcards. The format is scheme://host/path.
  • * in the scheme position matches any scheme (http or https).
  • * in the host matches a single domain label (*.example.com matches api.example.com but not a.b.example.com).
  • * in the path matches any substring including slashes.
Matching is case-insensitive.