1. Caddy version (caddy version
):
v2.4.5 h1:P1mRs6V2cMcagSPn+NWpD+OEYUYLIf6ecOa48cFGeUg=
2. How I run Caddy:
systemd
a. System environment:
Arch Linux, executing the binary
b. Command:
./caddy run -config Caddyfile
c. Service/unit/compose file:
N/A
d. My complete Caddyfile or JSON config:
:8081 {
tls internal
reverse_proxy https://caddyserver.com {
header_up Host {upstream_hostport}
header_up X-Forwarded-Host {host}
header_up -Accept-Encoding
@status_code {
status 200
expression `{http.reverse_proxy.header.server} == "Caddy"`
}
redir @status_code https://google.com
}
}
3. The problem I’m having:
I’m getting an error
4. Error messages and/or full log output:
2021/10/03 01:39:25.105 INFO using provided configuration {"config_file": "Caddyfile", "config_adapter": ""}
run: adapting config using caddyfile: parsing caddyfile tokens for 'reverse_proxy': Caddyfile:11 - Error during parsing: unrecognized response matcher expression
5. What I already tried:
None, as I cannot find any info about response matcher
. Only request matcher is available in docs.
6. Links to relevant resources:
expression
cannot be used to match responses. The only ones currently available are status
and header
, as described in the docs:
Also, you need to define a handle_response
block, under which you can define handler directives (like redir
).
That said, handle_response
currently has a bug that prevents it from working with any requests that have a non-empty response body. So it’s not currently possible to do what you’re trying to do, unfortunately.
opened 02:42AM - 22 Aug 21 UTC
closed 06:00PM - 18 Oct 21 UTC
bug
Following the [docs for `reverse_proxy` directive with `handle_response`](https:… //caddyserver.com/docs/caddyfile/directives/reverse_proxy#intercepting-responses) on a very basic JSON response endpoint results in failure, but modifying the header elsewhere in Caddy works as expected.
**Caddyfile (v2.4.3):**
```Caddyfile
:80 {
# Works:
#header Cache-Control "max-age=10"
reverse_proxy localhost:8000 {
handle_response {
# Errors:
header Cache-Control "max-age=10"
}
# Works:
#header_down Cache-Control "max-age=10"
}
}
```
**Error logged:**
```
2021/08/22 02:34:00.645 ERROR http.handlers.reverse_proxy reading from backend {"error": "http: read on closed response body"}
2021/08/22 02:34:00.645 ERROR http.handlers.reverse_proxy aborting with incomplete response {"error": "http: read on closed response body"}
```
The upstream still received the request and responded no differently AFAIK, in the web browser network tools Caddy has sent a response header but omitted the body.
---
For added context, intention was to match on `Content-Type application/json` rather than the URI; but AFAIK this is only available via the response, and thus can only be matched within `handle_response`? As the response matcher is not required to reproduce the error I have excluded it.
system
(system)
Closed
November 2, 2021, 1:43am
4
This topic was automatically closed after 30 days. New replies are no longer allowed.