A plugin for Caddy that will perform a regex replacement of POST body data.
- Go 72.8%
- JavaScript 27.2%
| replace-request | ||
| .gitignore | ||
| Caddyfile | ||
| ReadMe.md | ||
| test.js | ||
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:
- Start the backend Node app used to simulates the target web server processing API requests:
node test.js - Run the custom build of caddy:
./caddy run - Submit a curl request:
curl -X POST http://localhost:8000/pdf/ \
-H "Content-Type: application/json" \
-d '{
"foo": [
"bar"
],
"variables": {
"outpath": "c:/foo/bar"
}
}'
- Review console output from the Node app. Parsed JSON should show
OUTPATH. And the URI should show:/foobar/. Note: access.log will showoutpathand/pdf/.