Skip to content

v3.0.2

Choose a tag to compare

@labudzinski labudzinski released this 25 Apr 08:22
· 9 commits to main since this release

A single batch can now safely mix sub-requests that return any
Content-Type (JSON, problem+json, vendor +json, HTML, text, XML/SVG,
PDF, PNG, octet-stream, BinaryFileResponse, StreamedResponse, 204).
Previously binary bodies corrupted the outer JsonResponse envelope and
BinaryFileResponse/StreamedResponse payloads were silently dropped.

Changes

  • New Lemric\BatchRequest\Bridge\ResponseFormatter (framework-agnostic,
    shared by both bridges — works for Laravel too because
    Illuminate\Http\Response extends Symfony's and Laravel reuses
    Symfony's BinaryFileResponse/StreamedResponse).

    • JSON / */*+json → decoded array.
    • text/* and application/{xml,*+xml,javascript,yaml,…} → raw string.
    • Anything else → base64-encoded body + body_encoding: "base64".
    • BinaryFileResponse materialised via getFile().
    • StreamedResponse captured via output buffering.
    • Malformed JSON with a JSON content type stays as raw string
      (server claimed text, no base64).
    • Empty/no-content responses return "" (consistent string typing).
  • Symfony/SymfonyTransactionExecutor and
    Laravel/LaravelTransactionExecutor delegate response shaping to the
    new formatter; duplicated formatResponse/extractHeaders/
    isJsonContentType removed.

  • README: new "Mixed content types in a single batch" section with the
    Content-Type → body-shape table and an example mixed response.

Tests

  • New tests/Bridge/ResponseFormatterTest.php (17 cases) covers every
    branch and a mixed-batch round-trip through json_encode.
  • New tests/Bridge/ResponseFormatterLaravelTest.php (9 cases) proves
    the formatter handles Illuminate\Http\{Response,JsonResponse} and
    Symfony BinaryFileResponse/StreamedResponse returned by Laravel
    helpers.
  • SymfonyTransactionExecutorTest::testExecuteHandlesResponseWithoutContent
    updated: empty body is now "" instead of [].