Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Before this patch there was no way to reconstruct the invidual chunks that were sent. All we got was the full resulting body in `conn.resp_body`. For completeness, I believe instead of messaging we could store chunks in a list in the test adapter state and simply append: - def send_chunked(state, _status, _headers), do: {:ok, "", %{state | chunks: ""}} + def send_chunked(state, _status, _headers), do: {:ok, "", %{state | chunks: []}} - def chunk(%{owner: owner, ref: ref, chunks: chunks} = state, chunk) do - send(owner, {ref, :chunk, chunk}) - body = chunks <> IO.iodata_to_binary(chunk) - {:ok, body, %{state | chunks: body}} - end + def chunk(%{owner: owner, ref: ref, chunks: chunks} = state, chunk) do + chunk = IO.iodata_to_binary(chunk) + body = IO.iodata_to_binary([chunks, chunk]) + {:ok, body, %{state | chunks: chunks ++ [chunk]}} + end but I was following the existing functions `sent_informs` and `sent_upgrades`. My use case is to be able to test response streaming using Req :plug adapter: req = Req.new( plug: fn conn -> conn = Plug.Conn.send_chunked(conn, 200) {:ok, conn} = Plug.Conn.chunk(conn, "foo") {:ok, conn} = Plug.Conn.chunk(conn, "bar") conn end, into: [] ) resp = Req.request!(req) assert resp.body == ["foo", "bar"]
- Loading branch information