#7029·caddy

intercept: response headers and body are copied by default

Author: WeidiDengCreated May 20, 2025Updated Sep 28, 2026

When intercepting a response, response headers and body are copied by default, unlike in reverse_proxy where this behavior needs to be enabled explicitly.

Consider this Caddyfile:

localhost {
	log
	intercept {
		handle_response {
			respond "Hello, Caddy2!"
		}
	}
	reverse_proxy localhost:8080
}

http://localhost:8080/ {
	respond "Hello, World!"
}

This will cause curl to err with end of response with 13 bytes missing because the response failed to be written due to the content larger than the specified Content-Length. We can remove Content-Length manually in this case, but that adds unnecessary handling that could be avoided.

Sometimes it's also possible we just want to discard the original response body, it's not possible to do so for now.

It currently does not support the copy_response and copy_response_headers subdirectives, but it should be easy to add support for these features in future Pull Requests.

From @dunglas 's original pr it seemed like headers and body should be not copied by default. But the current behavior is they are being copied.