Skip to content

Add header logging toggle and isolate batching buffers#100

Open
rtsketo wants to merge 3 commits intoihsanbal:masterfrom
rtsketo:master
Open

Add header logging toggle and isolate batching buffers#100
rtsketo wants to merge 3 commits intoihsanbal:masterfrom
rtsketo:master

Conversation

@rtsketo
Copy link
Copy Markdown
Contributor

@rtsketo rtsketo commented Apr 7, 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

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