Skip to content

Conversation

@davoclavo
Copy link
Contributor

Hello!

After updating a project to v0.5.15 I noticed that things break if Req.Test is used with a plug and we set compress_body: true. This seems to be happening because a Plug.Parsers.call that was recently added to automatically parse the body; so in order to fix that we just need to make sure it is decompressed before doing so.

This is the error that shows up in the test I added (before the fix was applied)

  1) test compress_body compress_body works with plug adapter (Req.StepsTest)
     test/req/steps_test.exs:395
     ** (Plug.Parsers.ParseError) malformed request, a Jason.DecodeError exception was raised with message "unexpected byte at position 0: 0x1F"
     code: resp = Req.post!(plug: plug, json: %{test: "data"}, compress_body: true)
     stacktrace:
       (plug 1.16.1) lib/plug/parsers/json.ex:95: Plug.Parsers.JSON.decode/3
       (plug 1.16.1) lib/plug/parsers.ex:340: Plug.Parsers.reduce/8
       (req 0.5.15) lib/req/steps.ex:1042: Req.Steps.run_plug/1
       (req 0.5.15) lib/req/request.ex:1118: Req.Request.run_request/1
       (req 0.5.15) lib/req/request.ex:1062: Req.Request.run/1
       (req 0.5.15) lib/req.ex:1119: Req.request!/2
       test/req/steps_test.exs:403: (test)

@wojtekmach wojtekmach merged commit f0225a7 into wojtekmach:main Nov 10, 2025
2 checks passed
@wojtekmach
Copy link
Owner

Thank you so much, apologies for delay in getting this in!

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.

2 participants