Skip to content

Commit

Permalink
Update adapter docs suggested behaviour regarding chunk/2 return ty…
Browse files Browse the repository at this point in the history
…pes (#1204)
  • Loading branch information
mtrudel authored Jan 15, 2024
1 parent 5f244f4 commit 67cbc7c
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions lib/plug/conn/adapter.ex
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,11 @@ defmodule Plug.Conn.Adapter do
a chunked response to the client.
Webservers are advised to return `nil` as the sent_body,
as the body can no longer be manipulated. However, the
test implementation returns the actual body so it can
be used during testing.
since this function does not actually produce a body.
However, the test implementation returns an empty binary
as the body in order to be consistent with the built-up
body returned by subsequent calls to the test implementation's
`chunk/2` function
"""
@callback send_chunked(payload, status :: Conn.status(), headers :: Conn.headers()) ::
{:ok, sent_body :: binary | nil, payload}
Expand All @@ -97,13 +99,14 @@ defmodule Plug.Conn.Adapter do
If the request has method `"HEAD"`, the adapter should
not send the response to the client.
Webservers are advised to return `:ok` and not modify
any further state for each chunk. However, the test
implementation returns the actual body and payload so
it can be used during testing.
Webservers are advised to return `nil` as the sent_body,
since the complete sent body depends on the sum of all
calls to this function. However, the test implementation
tracks the overall body and payload so it can be used
during testing.
"""
@callback chunk(payload, body :: Conn.body()) ::
:ok | {:ok, sent_body :: binary, payload} | {:error, term}
:ok | {:ok, sent_body :: binary | nil, payload} | {:error, term}

@doc """
Reads the request body.
Expand Down

0 comments on commit 67cbc7c

Please sign in to comment.