caddy/modules/caddyhttp
long.black 16235cced5
Some checks are pending
Tests / test (./cmd/caddy/caddy, ~1.26.0, macos-14, 0, 1.26, mac) (push) Waiting to run
Tests / test (./cmd/caddy/caddy, ~1.26.0, ubuntu-latest, 0, 1.26, linux) (push) Waiting to run
Tests / test (./cmd/caddy/caddy.exe, ~1.26.0, windows-latest, True, 1.26, windows) (push) Waiting to run
Tests / test (s390x on IBM Z) (push) Waiting to run
Tests / goreleaser-check (push) Waiting to run
Cross-Build / build (~1.26.0, 1.26, aix) (push) Waiting to run
Cross-Build / build (~1.26.0, 1.26, darwin) (push) Waiting to run
Cross-Build / build (~1.26.0, 1.26, dragonfly) (push) Waiting to run
Cross-Build / build (~1.26.0, 1.26, freebsd) (push) Waiting to run
Cross-Build / build (~1.26.0, 1.26, illumos) (push) Waiting to run
Cross-Build / build (~1.26.0, 1.26, linux) (push) Waiting to run
Cross-Build / build (~1.26.0, 1.26, netbsd) (push) Waiting to run
Cross-Build / build (~1.26.0, 1.26, openbsd) (push) Waiting to run
Cross-Build / build (~1.26.0, 1.26, solaris) (push) Waiting to run
Cross-Build / build (~1.26.0, 1.26, windows) (push) Waiting to run
Lint / lint (push) Waiting to run
Lint / lint-1 (push) Waiting to run
Lint / lint-2 (push) Waiting to run
Lint / govulncheck (push) Waiting to run
Lint / dependency-review (push) Waiting to run
OpenSSF Scorecard supply-chain security / Scorecard analysis (push) Waiting to run
intercept: fix replace_status being silently dropped (#7810)
* test: add failing tests for intercept replace_status (#7805)

Add integration tests that verify replace_status actually substitutes
the HTTP status code sent to the client. Currently these tests fail
because replace_status is silently a no-op due to value-receiver
boxing and shouldBuffer returning false.

Tests added:
- TestInterceptReplaceStatusWithMatcher: 500 -> 200 with @err matcher
- TestInterceptReplaceStatusWithoutMatcher: 403 -> 200 unconditionally
- TestInterceptReplaceStatusNotMatched: 200 passes through unchanged

* fix: make intercept replace_status actually substitute the status code

Fix #7805: replace_status was silently a no-op because:
1. shouldBuffer returned false when a replacement status was set,
   causing the original status to be streamed directly to the wire
2. The value-receiver WriteHeader method operated on a stale copy

The fix:
- shouldBuffer now returns true when replace_status matches, so
  the response is buffered instead of streamed
- After next.ServeHTTP returns, if routes are nil (replace_status
  only), write the substituted status and buffered body to the client

The interceptedResponseHandler.WriteHeader substitution branch is no
longer needed for this path since substitution happens post-ServeHTTP.

* refactor: remove dead WriteHeader method and resolved TODO

The value-receiver WriteHeader on interceptedResponseHandler was
unreachable dead code — the substitution is now handled post-ServeHTTP
via buffering. Remove it along with the TODO comment that noted
status code replacement was unfinished.

* style: apply nit suggestions from dunglas code review

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

---------

Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-12 15:50:58 -06:00
..
caddyauth caddyauth: add candidate placeholders for rejected identities (#7698) 2026-05-20 13:51:54 +00:00
encode encode: add standard benchmark and conformance harness (#7804) 2026-06-11 17:55:18 -06:00
fileserver encode: add standard benchmark and conformance harness (#7804) 2026-06-11 17:55:18 -06:00
headers chore: Enable modernize linter (#7519) 2026-02-26 14:01:35 -07:00
intercept intercept: fix replace_status being silently dropped (#7810) 2026-06-12 15:50:58 -06:00
logging logging: log_append Early option, Supports {http.response.body} (#7368) 2025-12-16 23:42:42 -05:00
map chore: Use slices package where possible (#6585) 2024-09-25 14:30:56 -06:00
proxyprotocol docs: expand proxy protocol docs (#6620) 2024-10-10 16:21:26 -04:00
push chore: Dumb prealloc lint fix (#7430) 2026-01-13 14:13:43 -05:00
requestbody chore: ugh, lint fix... (#7275) 2025-09-26 03:14:48 -04:00
reverseproxy Merge commit from fork 2026-06-12 12:39:01 -06:00
rewrite rewrite: fix wrong index check in trimPathPrefix (#7812) 2026-06-12 14:11:21 -06:00
standard caddyhttp: New experimental handler for intercepting responses (#6232) 2024-05-13 17:38:18 +00:00
templates templates: Patch for GHSA-vcc4-2c75-vc9v (#7785) 2026-06-01 13:35:02 -06:00
tracing metrics: Implement pushing via OLTP (#7664) 2026-04-25 06:52:08 -04:00
app.go caddyhttp: New expected_underscore_headers server option (#7809) 2026-06-11 22:26:21 -06:00
autohttps.go tls: add alpn to managed HTTPS records (#7653) 2026-05-10 13:10:29 +10:00
autohttps_test.go tls: add alpn to managed HTTPS records (#7653) 2026-05-10 13:10:29 +10:00
caddyhttp.go caddyhttp: Add MatchWithError to replace SetVar hack (#6596) 2024-11-04 23:18:50 +00:00
caddyhttp_test.go caddyhttp: Add test cases to corpus (#6374) 2024-06-04 14:23:55 -06:00
celmatcher.go chore: clean up wording and typo fixes (#7745) 2026-05-20 16:36:30 +10:00
celmatcher_test.go chore: clean up wording and typo fixes (#7745) 2026-05-20 16:36:30 +10:00
errors.go use math/rand/v2 instead of math/rand (#7413) 2026-02-11 09:15:51 -07:00
http2listener.go chore: clean up wording and typo fixes (#7745) 2026-05-20 16:36:30 +10:00
httpredirectlistener.go chore: clean up wording and typo fixes (#7745) 2026-05-20 16:36:30 +10:00
invoke.go
ip_matchers.go caddyhttp: refactor to use reflect.TypeFor (#7187) 2025-08-18 17:08:46 -06:00
ip_range.go Move PrivateRangesCIDR() back: add a pass-through function (#6514) 2024-08-12 05:47:05 -04:00
logging.go core: custom slog handlers for modules (log contextual data) (#7346) 2025-11-12 13:29:47 -07:00
marshalers.go admin: Redact sensitive request headers in API logs (#7578) 2026-04-17 14:56:42 -06:00
matchers.go caddyhttp: normalize Windows backslashes in path matcher (#7763) 2026-05-21 11:28:40 -06:00
matchers_test.go caddyhttp: normalize Windows backslashes in path matcher (#7763) 2026-05-21 11:28:40 -06:00
metrics.go metrics: Implement pushing via OLTP (#7664) 2026-04-25 06:52:08 -04:00
metrics_test.go metrics: Implement pushing via OLTP (#7664) 2026-04-25 06:52:08 -04:00
replacer.go caddyhttp: add {http.request.proto_name} placeholder for spec-compliant protocol names (#7782) 2026-06-04 11:03:19 -04:00
replacer_test.go caddyhttp: add {http.request.proto_name} placeholder for spec-compliant protocol names (#7782) 2026-06-04 11:03:19 -04:00
responsematchers.go caddyhttp: Allow matching Transfer-Encoding, add to access logs (#6629) 2024-12-20 11:16:34 -07:00
responsematchers_test.go
responsewriter.go caddyhttp: ResponseRecorder sets stream regardless of 1xx 2025-01-27 08:18:37 -07:00
responsewriter_test.go caddyhttp: Address some Go 1.20 features (#6252) 2024-04-24 00:05:57 +00:00
routes.go chore: Fix golangci-lint 2.12.1 findings (#7690) 2026-05-07 03:40:26 -04:00
server.go caddyhttp: New expected_underscore_headers server option (#7809) 2026-06-11 22:26:21 -06:00
server_test.go caddyhttp: New expected_underscore_headers server option (#7809) 2026-06-11 22:26:21 -06:00
staticerror.go caddyhttp: run error (msg) through replacer (#6536) 2024-08-22 11:32:44 -06:00
staticresp.go chore: Add nolints to work around haywire linters (#7493) 2026-02-17 16:52:54 -07:00
staticresp_test.go
subroute.go
vars.go vars: Don't expand placeholders in values (#7629) 2026-04-10 09:37:43 -06:00
vars_test.go vars: Add matcher placeholder handling tests (#7640) 2026-04-10 16:27:52 -06:00