Don't override user-agent header if it's been set
authorRoman Chvanikov <chvanikoff@pm.me>
Sat, 1 Aug 2020 07:04:25 +0000 (10:04 +0300)
committerRoman Chvanikov <chvanikoff@pm.me>
Sat, 1 Aug 2020 07:04:25 +0000 (10:04 +0300)
lib/pleroma/http/request_builder.ex

index 2fc876d924017f9d55a8d5d9cf3dd108e22fff02..8a44a001dbabc87e41f4f17936d5879af343cda6 100644 (file)
@@ -34,10 +34,12 @@ 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
+      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
+        _ ->
+          headers
       end
 
     %{request | headers: headers_list}