1. The problem I’m having:
I am using caddy, built using xcaddy
, with the “non-standard” module replace-response to manipulate the content of the response. My goal is to find the phrase “localhost” and replace it with the value of the placeholder {http.request.host}
, in my case an IPv4 address. Therefore I created this configuration
...
"handle":[
{
"handler":"replace_response",
"replacements":[
{
"search":"localhost",
"replace":"{http.request.host}"
}
]
}
]
...
As I can see in the response, this does not work. The replacement is done correctly, but instead of the expected value from the original request content "Hi, I replaced localhost"
to e.g. "Hi, I replaced 192.168.172.36"
, the placeholder itself is placed: "Hi, I replaced {http.request.host}"
.
The same goes for a normal static_response
. So I am not suspecting the module to be the problem.
2. Error messages and/or full log output:
2023/07/12 15:48:22.686 INFO using provided configuration {"config_file": "caddy-replace.json", "config_adapter": ""}
2023/07/12 15:48:22.687 INFO admin admin endpoint started {"address": "localhost:2019", "enforce_origin": false, "origins": ["//localhost:2019", "//[::1]:2019", "//127.0.0.1:2019"]}
2023/07/12 15:48:22.687 INFO tls.cache.maintenance started background certificate maintenance {"cache": "0xc0000fdf10"}
2023/07/12 15:48:22.687 INFO tls cleaning storage unit {"description": "FileStorage:/home/user/.local/share/caddy"}
2023/07/12 15:48:22.687 INFO http.log server running {"name": "example", "protocols": ["h1", "h2", "h3"]}
2023/07/12 15:48:22.687 INFO tls finished cleaning storage units
2023/07/12 15:48:22.687 INFO autosaved config (load with --resume flag) {"file": "/home/user/.config/caddy/autosave.json"}
2023/07/12 15:48:22.688 INFO serving initial configuration
3. Caddy version:
user@ubuntu:~/Documents/caddy/xcaddy$ ./caddy version
v2.6.4 h1:2hwYqiRwk1tf3VruhMpLcYTg+11fCdr8S3jhNAdnPy8=
4. How I installed and ran Caddy:
Static self built binary via xcaddy
./caddy run --config caddy-replace.json
a. System environment:
Ubuntu
d. My complete Caddy config:
{
"apps": {
"http": {
"servers": {
"example": {
"listen": [
":2015"
],
"routes": [
{
"handle": [
{
"handler": "replace_response",
"replacements": [
{
"search": "localhost",
"replace": "{http.request.host}"
}
]
},
{
"handler": "static_response",
"body": "Hi, I replaced localhost"
}
]
}
]
}
}
}
}
}