Skip to content

Making removal of space from JSON encoding configurable and documenting the behaviour #3563

Closed

Description

@skippednote

This is regarding the issue #3363 which was fixed as a part of #3367.

We discovered that manually encoding the JSON versus using HTTPX’s built-in encoding produces different outputs due to missing spaces, this in our case broke our cryptographic signature validation.
Could we add a note about this in the docs and perhaps expose a flag to disable HTTPX’s JSON encoder?

Activity

  1. lovelydinosaur commented on May 6, 2025

    @lovelydinosaur
    Member

    The compact style is documented in the 0.28.0 release notes. We will not be adding a switch for this behavior.

  2. eightyeighteyes commented on Sep 16, 2025

    @eightyeighteyes

    This actually does more than the CHANGELOG says: it doesn't just require us to change our test suites, it requires us to change the way that we create signed requests, and the only way to understand that is to go diving into past PRs in this repository to understand what exactly the change is and how to work around it.

    In our specific case, this change breaks AWS V4 request signing by changing the content of the request body sent, so it no longer matches the content that was used to create the request signature. I believe the specific change that is causing the problem is the removal of spaces between separators.

    From the perspective of a user of the library, I definitely don't expect that the request content body will be transformed in flight. To work around it, I need to use the same JSON encoding that httpx uses under the hood in a private module and emulate that when signing my request, but this isn't explicitly declared in either the changelog or httpx docs.

    So, no, it's not enough to say "the compact style is documented in the release notes". This breaks the way cryptographic signing works, simple as, and essentially means we, as users, need to follow very specific, obscure encoding of content to make it compatible with your library, or we just need to never update past 0.27.

    Please consider reverting the change where content is transformed in flight (and, if a user desires a compact format, leave that up to them), or let us configure the behavior at the time we make a request.

  3. lovelydinosaur commented on Sep 16, 2025

    @lovelydinosaur
    Member

    This actually does more than the CHANGELOG says

    No. It does exactly what the CHANGELOG entry states.

    "JSON request bodies use a compact representation." (#3363)

    Please consider reverting the change where content is transformed in flight

    Nothing is changed "in flight".

    You're welcome to pin to earlier versions if you want a verbose JSON encoding by default.

  4. lovelydinosaur commented on Oct 7, 2025

    @lovelydinosaur
    Member

    Banning the trolls for trolling, and deleting the pointless gumpf.

  5. deleted a comment from malkstar on Oct 7, 2025
  6. deleted a comment from eightyeighteyes on Oct 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions