Skip to content

Conversation

@francislavoie
Copy link
Member

@francislavoie francislavoie commented Nov 26, 2025

Related to #7367, I wanted some more conveniences for logging request/response bodies.

  • Adding a < prefix to the log_append key to enable the Early option; makes log_append pull the value and add to the log on the way in (default is doing it on the way out, after the terminal response handler ran). This is necessary to be able to use {http.request.body} because it has to apply the request body buffer before it calls reverse_proxy or whatever.

  • Adding a special case to log_append to allow buffering and logging the response body. This isn't implemented as an actual placeholder because placeholders aren't able to replace w since the placeholder-replacer is created at the start of the request and it would be impossible to replace w in a callback and affect the callback chain. Also added a {http.response.body_base64} for the same reason as in caddyhttp: {http.request.body_base64} placeholder #7367, e.g. when the body is binary or whatever.

Caddyfile for testing:

:8001 {
    log
    log_append <req_body {http.request.body}
    log_append resp_body {http.response.body}
    reverse_proxy localhost:8002
}

:8002 {
    respond "hello world this should work"
}

Test:

$ curl -v http://localhost:8001 -d "foo bar"

Log ends up with:

..."req_body": "foo bar", "resp_body": "hello world this should work"...

Assistance Disclosure

Used Github Copilot (Sonnet 4.5, GPT-5)

@francislavoie francislavoie added this to the v2.11.0 milestone Nov 26, 2025
@francislavoie francislavoie added the feature ⚙️ New feature or request label Nov 26, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature ⚙️ New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants