X-Git-Url: http://git.squeep.com/?a=blobdiff_plain;f=lib%2Fpleroma%2Fhttp%2Frequest_builder.ex;h=4cd75d3a008a597ea2c5c9b62021aac5cc5ae7da;hb=364b6969eb7c79e57ed02345ddff4f48519e6b0a;hp=2fc876d924017f9d55a8d5d9cf3dd108e22fff02;hpb=cf2a0574e77ed207453215ae83377a3eb8f2fa0c;p=akkoma diff --git a/lib/pleroma/http/request_builder.ex b/lib/pleroma/http/request_builder.ex index 2fc876d92..4cd75d3a0 100644 --- a/lib/pleroma/http/request_builder.ex +++ b/lib/pleroma/http/request_builder.ex @@ -1,5 +1,5 @@ # Pleroma: A lightweight social networking server -# Copyright © 2017-2020 Pleroma Authors +# Copyright © 2017-2021 Pleroma Authors # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.HTTP.RequestBuilder do @@ -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,12 +35,7 @@ defmodule Pleroma.HTTP.RequestBuilder do """ @spec headers(Request.t(), Request.headers()) :: Request.t() def headers(request, headers) do - headers_list = - if Pleroma.Config.get([:http, :send_user_agent]) 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 @@ -90,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