Skip to content

Add optional response header logging and isolate batching buffers#99

Closed
rtsketo wants to merge 3 commits intoihsanbal:masterfrom
rtsketo:codex/response-headers-batching-fix
Closed

Add optional response header logging and isolate batching buffers#99
rtsketo wants to merge 3 commits intoihsanbal:masterfrom
rtsketo:codex/response-headers-batching-fix

Conversation

@rtsketo
Copy link
Copy Markdown
Contributor

@rtsketo rtsketo commented Apr 6, 2026

Problem

The library had two separate issues.

  1. Response logs never printed response headers.
    Printer.printJsonResponse(...) only emitted the response URL, the Status Code: line, and then the existing Body: block for BASIC/BODY. There was no response-side equivalent of the request header output, so downstream apps had to add their own manual response.headers logging when they needed headers such as x-authentication-token.

  2. BatchingSink could corrupt its internal buffer under concurrent logging.
    The sink stored buffers in a ConcurrentHashMap, but the key was only the log tag. When two requests logged at the same time with the same tag, both threads could append into the same StringBuilder. StringBuilder is not thread-safe, so concurrent mutation could interleave blocks and trigger crashes such as StringIndexOutOfBoundsException from BatchingSink.log(...).

Fix

  • add a logHeaders(enabled) builder flag, defaulting to true, to control both request and response header sections
  • keep the existing Body: behavior unchanged
  • continue honoring current request Level behavior while adding the missing response header block under Status Code:
  • isolate BatchingSink buffers by tag and current thread so concurrent same-tag request/response blocks no longer share one mutable StringBuilder
  • add JVM tests for request/response header output and concurrent batching isolation

Testing

  • .\\gradlew.bat :lib:test :lib:build

@rtsketo
Copy link
Copy Markdown
Contributor Author

rtsketo commented Apr 7, 2026

Replacing this with #100 from rtsketo:master.

@rtsketo rtsketo closed this Apr 7, 2026
@rtsketo rtsketo deleted the codex/response-headers-batching-fix branch April 7, 2026 05:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant