summaryrefslogtreecommitdiff
path: root/test/support/http_request_mock.ex
diff options
context:
space:
mode:
authorrinpatch <rinpatch@sdf.org>2020-09-14 14:45:58 +0300
committerrinpatch <rinpatch@sdf.org>2020-09-14 14:45:58 +0300
commitf70335002df9b2b3f47f0ccaed6aaeebfb14435f (patch)
tree16c15bdcdf5c5260e58fae9947075aca7d80687a /test/support/http_request_mock.ex
parentf66a15c4a51e1c8f614b4c1609b2385a29762931 (diff)
downloadpleroma-f70335002df9b2b3f47f0ccaed6aaeebfb14435f.tar.gz
pleroma-f70335002df9b2b3f47f0ccaed6aaeebfb14435f.zip
RichMedia: Do a HEAD request to check content type/length
This shouldn't be too expensive, since the connections are pooled, but it should save us some bandwidth since we won't fetch non-html files and files that are too large for us to process (especially since you can't cancel a request without closing the connection with HTTP1).
Diffstat (limited to 'test/support/http_request_mock.ex')
-rw-r--r--test/support/http_request_mock.ex17
1 files changed, 17 insertions, 0 deletions
diff --git a/test/support/http_request_mock.ex b/test/support/http_request_mock.ex
index 344e27f13..cb022333f 100644
--- a/test/support/http_request_mock.ex
+++ b/test/support/http_request_mock.ex
@@ -1262,4 +1262,21 @@ defmodule HttpRequestMock do
inspect(headers)
}"}
end
+
+ # Most of the rich media mocks are missing HEAD requests, so we just return 404.
+ @rich_media_mocks [
+ "https://example.com/ogp",
+ "https://example.com/ogp-missing-data",
+ "https://example.com/twitter-card"
+ ]
+ def head(url, _query, _body, _headers) when url in @rich_media_mocks do
+ {:ok, %Tesla.Env{status: 404, body: ""}}
+ end
+
+ def head(url, query, body, headers) do
+ {:error,
+ "Mock response not implemented for HEAD #{inspect(url)}, #{query}, #{inspect(body)}, #{
+ inspect(headers)
+ }"}
+ end
end