Closed tomasz-tomczyk closed 2 years ago
I believe in this case the better option is to always pass the body as a string, instead of parameters (i.e. make the third argument of get/3
a string). Would that work?
You're right, I think I assumed the data was provided by params somehow, but this works fine:
assert {:ok, _body, conn} =
conn(:get, "/test", "{\"hello\":\"world\"")
|> RawBody.cache_raw_body()
assert conn.assigns.raw_body == ["{\"hello\":\"world\""]
assert {:ok, _body, conn} =
conn(:post, "/test", "{\"hello\":\"world\"")
|> RawBody.cache_raw_body()
assert conn.assigns.raw_body == ["{\"hello\":\"world\""]
I'll close, thanks!
I'm writing a small utility function that caches the raw body of the request as suggested in https://github.com/elixir-plug/plug/issues/691 and https://hexdocs.pm/plug/Plug.Parsers.html#module-custom-body-reader that looks like the following:
When writing a test for it I couldn't get the real values
I thought it might be good to expose the params in both
GET
andPOST
handlers, but let me know if I misunderstood anything!