Use uppercase HTTP HEAD method for media preview proxy request (#128)
Reviewed-on: https://akkoma.dev/AkkomaGang/akkoma/pulls/128 Co-authored-by: Yukkuri <iamtakingiteasy@eientei.org> Co-committed-by: Yukkuri <iamtakingiteasy@eientei.org>
This commit is contained in:
parent
2033d7d4fc
commit
38659e5610
|
@ -54,7 +54,7 @@ defp handle_preview(conn, url) do
|
||||||
media_proxy_url = MediaProxy.url(url)
|
media_proxy_url = MediaProxy.url(url)
|
||||||
|
|
||||||
with {:ok, %{status: status} = head_response} when status in 200..299 <-
|
with {:ok, %{status: status} = head_response} when status in 200..299 <-
|
||||||
Pleroma.HTTP.request("head", media_proxy_url, [], [], name: MyFinch) do
|
Pleroma.HTTP.request("HEAD", media_proxy_url, [], [], name: MyFinch) do
|
||||||
content_type = Tesla.get_header(head_response, "content-type")
|
content_type = Tesla.get_header(head_response, "content-type")
|
||||||
content_length = Tesla.get_header(head_response, "content-length")
|
content_length = Tesla.get_header(head_response, "content-length")
|
||||||
content_length = content_length && String.to_integer(content_length)
|
content_length = content_length && String.to_integer(content_length)
|
||||||
|
|
|
@ -158,7 +158,7 @@ test "responds with 424 Failed Dependency if HEAD request to media proxy fails",
|
||||||
media_proxy_url: media_proxy_url
|
media_proxy_url: media_proxy_url
|
||||||
} do
|
} do
|
||||||
Tesla.Mock.mock(fn
|
Tesla.Mock.mock(fn
|
||||||
%{method: "head", url: ^media_proxy_url} ->
|
%{method: "HEAD", url: ^media_proxy_url} ->
|
||||||
%Tesla.Env{status: 500, body: ""}
|
%Tesla.Env{status: 500, body: ""}
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
@ -173,7 +173,7 @@ test "redirects to media proxy URI on unsupported content type", %{
|
||||||
media_proxy_url: media_proxy_url
|
media_proxy_url: media_proxy_url
|
||||||
} do
|
} do
|
||||||
Tesla.Mock.mock(fn
|
Tesla.Mock.mock(fn
|
||||||
%{method: "head", url: ^media_proxy_url} ->
|
%{method: "HEAD", url: ^media_proxy_url} ->
|
||||||
%Tesla.Env{status: 200, body: "", headers: [{"content-type", "application/pdf"}]}
|
%Tesla.Env{status: 200, body: "", headers: [{"content-type", "application/pdf"}]}
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
@ -193,7 +193,7 @@ test "with `static=true` and GIF image preview requested, responds with JPEG ima
|
||||||
clear_config([:media_preview_proxy, :min_content_length], 1_000_000_000)
|
clear_config([:media_preview_proxy, :min_content_length], 1_000_000_000)
|
||||||
|
|
||||||
Tesla.Mock.mock(fn
|
Tesla.Mock.mock(fn
|
||||||
%{method: "head", url: ^media_proxy_url} ->
|
%{method: "HEAD", url: ^media_proxy_url} ->
|
||||||
%Tesla.Env{
|
%Tesla.Env{
|
||||||
status: 200,
|
status: 200,
|
||||||
body: "",
|
body: "",
|
||||||
|
@ -218,7 +218,7 @@ test "with GIF image preview requested and no `static` param, redirects to media
|
||||||
media_proxy_url: media_proxy_url
|
media_proxy_url: media_proxy_url
|
||||||
} do
|
} do
|
||||||
Tesla.Mock.mock(fn
|
Tesla.Mock.mock(fn
|
||||||
%{method: "head", url: ^media_proxy_url} ->
|
%{method: "HEAD", url: ^media_proxy_url} ->
|
||||||
%Tesla.Env{status: 200, body: "", headers: [{"content-type", "image/gif"}]}
|
%Tesla.Env{status: 200, body: "", headers: [{"content-type", "image/gif"}]}
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
@ -236,7 +236,7 @@ test "with `static` param and non-GIF image preview requested, " <>
|
||||||
media_proxy_url: media_proxy_url
|
media_proxy_url: media_proxy_url
|
||||||
} do
|
} do
|
||||||
Tesla.Mock.mock(fn
|
Tesla.Mock.mock(fn
|
||||||
%{method: "head", url: ^media_proxy_url} ->
|
%{method: "HEAD", url: ^media_proxy_url} ->
|
||||||
%Tesla.Env{status: 200, body: "", headers: [{"content-type", "image/jpeg"}]}
|
%Tesla.Env{status: 200, body: "", headers: [{"content-type", "image/jpeg"}]}
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
@ -256,7 +256,7 @@ test "with :min_content_length setting not matched by Content-Length header, " <
|
||||||
clear_config([:media_preview_proxy, :min_content_length], 100_000)
|
clear_config([:media_preview_proxy, :min_content_length], 100_000)
|
||||||
|
|
||||||
Tesla.Mock.mock(fn
|
Tesla.Mock.mock(fn
|
||||||
%{method: "head", url: ^media_proxy_url} ->
|
%{method: "HEAD", url: ^media_proxy_url} ->
|
||||||
%Tesla.Env{
|
%Tesla.Env{
|
||||||
status: 200,
|
status: 200,
|
||||||
body: "",
|
body: "",
|
||||||
|
@ -278,7 +278,7 @@ test "thumbnails PNG images into PNG", %{
|
||||||
assert_dependencies_installed()
|
assert_dependencies_installed()
|
||||||
|
|
||||||
Tesla.Mock.mock(fn
|
Tesla.Mock.mock(fn
|
||||||
%{method: "head", url: ^media_proxy_url} ->
|
%{method: "HEAD", url: ^media_proxy_url} ->
|
||||||
%Tesla.Env{status: 200, body: "", headers: [{"content-type", "image/png"}]}
|
%Tesla.Env{status: 200, body: "", headers: [{"content-type", "image/png"}]}
|
||||||
|
|
||||||
%{method: :get, url: ^media_proxy_url} ->
|
%{method: :get, url: ^media_proxy_url} ->
|
||||||
|
@ -300,7 +300,7 @@ test "thumbnails JPEG images into JPEG", %{
|
||||||
assert_dependencies_installed()
|
assert_dependencies_installed()
|
||||||
|
|
||||||
Tesla.Mock.mock(fn
|
Tesla.Mock.mock(fn
|
||||||
%{method: "head", url: ^media_proxy_url} ->
|
%{method: "HEAD", url: ^media_proxy_url} ->
|
||||||
%Tesla.Env{status: 200, body: "", headers: [{"content-type", "image/jpeg"}]}
|
%Tesla.Env{status: 200, body: "", headers: [{"content-type", "image/jpeg"}]}
|
||||||
|
|
||||||
%{method: :get, url: ^media_proxy_url} ->
|
%{method: :get, url: ^media_proxy_url} ->
|
||||||
|
@ -320,7 +320,7 @@ test "redirects to media proxy URI in case of thumbnailing error", %{
|
||||||
media_proxy_url: media_proxy_url
|
media_proxy_url: media_proxy_url
|
||||||
} do
|
} do
|
||||||
Tesla.Mock.mock(fn
|
Tesla.Mock.mock(fn
|
||||||
%{method: "head", url: ^media_proxy_url} ->
|
%{method: "HEAD", url: ^media_proxy_url} ->
|
||||||
%Tesla.Env{status: 200, body: "", headers: [{"content-type", "image/jpeg"}]}
|
%Tesla.Env{status: 200, body: "", headers: [{"content-type", "image/jpeg"}]}
|
||||||
|
|
||||||
%{method: :get, url: ^media_proxy_url} ->
|
%{method: :get, url: ^media_proxy_url} ->
|
||||||
|
|
Loading…
Reference in a new issue