docs(http): update hackney comments for 4.9
This commit is contained in:
parent
48ec8518a3
commit
26486b041b
3 changed files with 14 additions and 17 deletions
|
|
@ -7,16 +7,14 @@ defmodule Pleroma.Tesla.Middleware.MaxBody do
|
||||||
Enforces the `:max_body` adapter option for every adapter.
|
Enforces the `:max_body` adapter option for every adapter.
|
||||||
|
|
||||||
`Pleroma.HTTP.Adapter.Gun` applies the limit as it accumulates a `:plain`
|
`Pleroma.HTTP.Adapter.Gun` applies the limit as it accumulates a `:plain`
|
||||||
body, so an oversized response is abandoned mid-transfer. Hackney cannot:
|
body, so an oversized response is abandoned mid-transfer. Since 4.9 Hackney
|
||||||
since 4.0 it ignores `with_body` and always hands back a fully read binary
|
does the same with the `max_body` request option. Before that it ignored
|
||||||
(`hackney:request/5`), so `Tesla.Adapter.Hackney` never takes the branch that
|
`with_body` and always handed back a fully read binary (`hackney:request/5`),
|
||||||
would honour `:max_body`. Without this middleware the option is silently
|
so `Tesla.Adapter.Hackney` never took the branch that would honour
|
||||||
unenforced there.
|
`:max_body`.
|
||||||
|
|
||||||
The check therefore bounds what callers are handed, and refuses up front when
|
The check bounds what callers are handed, whatever the adapter does, and
|
||||||
`content-length` already announces too much. It cannot bound peak memory on
|
refuses up front when `content-length` already announces too much.
|
||||||
the hackney path, because the adapter has read the body before any middleware
|
|
||||||
runs.
|
|
||||||
|
|
||||||
Streaming bodies are left alone: neither adapter limits those, and the caller
|
Streaming bodies are left alone: neither adapter limits those, and the caller
|
||||||
that owns the stream is the one that has to drain and release it.
|
that owns the stream is the one that has to drain and release it.
|
||||||
|
|
|
||||||
|
|
@ -14,16 +14,15 @@
|
||||||
#
|
#
|
||||||
# Pleroma cannot work around this: since 4.0 Hackney ignores `with_body` and
|
# Pleroma cannot work around this: since 4.0 Hackney ignores `with_body` and
|
||||||
# always returns a fully read binary, so a synchronous request never yields a
|
# always returns a fully read binary, so a synchronous request never yields a
|
||||||
# handle to close. Up to 4.8 a truncated read also reported `{:ok, body}`;
|
# handle to close. Up to 4.8.2 a truncated read also reported `{:ok, body}`;
|
||||||
# since 4.9 it is `{:error, {:closed, partial_body}}`.
|
# since 4.8.3 it is `{:error, {:closed, partial_body}}`.
|
||||||
#
|
#
|
||||||
# Media proxy warming hits this whenever an attachment fetch is cut short and
|
# Media proxy warming hits this whenever an attachment fetch is cut short and
|
||||||
# the outbound proxy is used as a CONNECT tunnel, since tunnels are never
|
# the outbound proxy is used as a CONNECT tunnel, since tunnels are never
|
||||||
# pooled. That is how it was found.
|
# pooled. That is how it was found.
|
||||||
#
|
#
|
||||||
# Fixed upstream by https://github.com/benoitc/hackney/pull/919; mix.exs pins
|
# Fixed upstream by https://github.com/benoitc/hackney/pull/919. Should this
|
||||||
# that commit until it lands in a release. Should this start failing, the pin
|
# start failing, mix.exs has moved to a Hackney version without the fix.
|
||||||
# has been moved to a version without the fix.
|
|
||||||
#
|
#
|
||||||
# https://github.com/benoitc/hackney/issues/918
|
# https://github.com/benoitc/hackney/issues/918
|
||||||
defmodule Pleroma.HTTP.HackneyConnLeakTest do
|
defmodule Pleroma.HTTP.HackneyConnLeakTest do
|
||||||
|
|
|
||||||
|
|
@ -44,8 +44,8 @@ defmodule Pleroma.HTTP.HackneyMaxBodyRegressionTest do
|
||||||
request("#{server.base_url}/big", max_body: 1024)
|
request("#{server.base_url}/big", max_body: 1024)
|
||||||
end
|
end
|
||||||
|
|
||||||
# Without a Content-Length the header pre-check cannot fire, so this is the
|
# Without a Content-Length the header pre-check cannot fire, so only a size
|
||||||
# case that proves hackney's fully-read binary is measured.
|
# check on the body can refuse this.
|
||||||
test "a chunked body over max_body is refused on size alone", %{server: server} do
|
test "a chunked body over max_body is refused on size alone", %{server: server} do
|
||||||
assert {:error, :body_too_large} =
|
assert {:error, :body_too_large} =
|
||||||
request("#{server.base_url}/chunked", max_body: 1024)
|
request("#{server.base_url}/chunked", max_body: 1024)
|
||||||
|
|
@ -58,7 +58,7 @@ defmodule Pleroma.HTTP.HackneyMaxBodyRegressionTest do
|
||||||
assert byte_size(body) == @body_bytes
|
assert byte_size(body) == @body_bytes
|
||||||
end
|
end
|
||||||
|
|
||||||
test "without max_body the body is returned whatever its size", %{server: server} do
|
test "without max_body the body is returned", %{server: server} do
|
||||||
assert {:ok, %Tesla.Env{status: 200, body: body}} = request("#{server.base_url}/big", [])
|
assert {:ok, %Tesla.Env{status: 200, body: body}} = request("#{server.base_url}/big", [])
|
||||||
assert byte_size(body) == @body_bytes
|
assert byte_size(body) == @body_bytes
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue