X-Git-Url: https://git.squeep.com/?a=blobdiff_plain;f=lib%2Fpleroma%2Fhttp%2Frequest_builder.ex;h=4cd75d3a008a597ea2c5c9b62021aac5cc5ae7da;hb=18bf82d7479b0bb767a657e1b7447529f9c2884f;hp=631c927af2b35a9e9d34bba6555658099b4a998f;hpb=cf367fdbd53b50f4324a01ddabdc0520cd787321;p=akkoma diff --git a/lib/pleroma/http/request_builder.ex b/lib/pleroma/http/request_builder.ex index 631c927af..4cd75d3a0 100644 --- a/lib/pleroma/http/request_builder.ex +++ b/lib/pleroma/http/request_builder.ex @@ -10,6 +10,8 @@ defmodule Pleroma.HTTP.RequestBuilder do alias Pleroma.HTTP.Request alias Tesla.Multipart + @mix_env Mix.env() + @doc """ Creates new request """ @@ -33,14 +35,7 @@ defmodule Pleroma.HTTP.RequestBuilder do """ @spec headers(Request.t(), Request.headers()) :: Request.t() def headers(request, headers) do - headers_list = - with true <- Pleroma.Config.get([:http, :send_user_agent]), - nil <- Enum.find(headers, fn {key, _val} -> String.downcase(key) == "user-agent" end) do - [{"user-agent", Pleroma.Application.user_agent()} | headers] - else - _ -> - headers - end + headers_list = maybe_add_user_agent(headers, @mix_env) %{request | headers: headers_list} end @@ -92,4 +87,16 @@ defmodule Pleroma.HTTP.RequestBuilder do |> Map.from_struct() |> Enum.into([]) end + + defp maybe_add_user_agent(headers, :test) do + with true <- Pleroma.Config.get([:http, :send_user_agent]) do + [{"user-agent", Pleroma.Application.user_agent()} | headers] + else + _ -> + headers + end + end + + defp maybe_add_user_agent(headers, _), + do: [{"user-agent", Pleroma.Application.user_agent()} | headers] end