A plugin for Caddy that will perform a regex replacement of POST body data.
  • Go 72.8%
  • JavaScript 27.2%
Find a file
2026-08-20 18:21:46 +10:00
replace-request Initial commit 2026-08-20 18:21:46 +10:00
.gitignore Initial commit 2026-08-20 18:21:46 +10:00
Caddyfile Initial commit 2026-08-20 18:21:46 +10:00
ReadMe.md Initial commit 2026-08-20 18:21:46 +10:00
test.js Initial commit 2026-08-20 18:21:46 +10:00

Overview

A request-replace plugin for Caddy that will perform a regex replacement of POST body data.

Designed to replace keys/values in JSON payloads. For example: outpath to OUTPATH.

Build

Ensure go is installed. And xcaddy. Assuming xcaddy is located under ~/go/bin/, run the following to build a custom version of Caddy that includes the request-replace plugin defined in this repo, and the exisitng community plugin name replace-response:

~/go/bin/xcaddy build \
  --with github.com/caddyserver/replace-response \
  --with github.com/comcare/replace-request=./replace-request

If needed, use the following command to install xcaddy:

go install github.com/caddyserver/xcaddy/cmd/xcaddy@latest

Test

To test:

  1. Start the backend Node app used to simulates the target web server processing API requests: node test.js
  2. Run the custom build of caddy: ./caddy run
  3. Submit a curl request:
curl -X POST http://localhost:8000/pdf/ \
-H "Content-Type: application/json" \
-d '{
  "foo": [
    "bar"
  ],
  "variables": {
    "outpath": "c:/foo/bar"
  }
}'
  1. Review console output from the Node app. Parsed JSON should show OUTPATH. And the URI should show: /foobar/. Note: access.log will show outpath and /pdf/.