+ defp proxy_request_body(client), do: proxy_request_body(client, <<>>)
+
+ defp proxy_request_body(client, body) when byte_size(body) < @max_body_length do
+ case :hackney.stream_body(client) do
+ {:ok, data} -> proxy_request_body(client, <<body::binary, data::binary>>)
+ :done -> {:ok, body}
+ {:error, reason} -> {:error, reason}
+ end
+ end
+
+ defp proxy_request_body(client, _) do
+ :hackney.close(client)
+ {:error, :body_too_large}
+ end
+
+ # TODO: the body is passed here as well because some hosts do not provide a content-type.
+ # At some point we may want to use magic numbers to discover the content-type and reply a proper one.
+ defp proxy_request_content_type(headers, _body) do
+ headers["Content-Type"] || headers["content-type"] || "image/jpeg"
+ end