Merge branch 'feature/useragent-override' into 'develop'

Add ability to set a custom user-agent string

See merge request pleroma/pleroma!2009
This commit is contained in:
rinpatch 2019-11-25 11:36:59 +00:00
commit 756bdef5f5
4 changed files with 30 additions and 3 deletions

View file

@ -209,6 +209,7 @@
config :pleroma, :http, config :pleroma, :http,
proxy_url: nil, proxy_url: nil,
send_user_agent: true, send_user_agent: true,
user_agent: :default,
adapter: [ adapter: [
ssl_options: [ ssl_options: [
# Workaround for remote server certificate chain issues # Workaround for remote server certificate chain issues

View file

@ -348,7 +348,17 @@ Available caches:
* `:activity_pub` - activity pub routes (except question activities). Defaults to `nil` (no expiration). * `:activity_pub` - activity pub routes (except question activities). Defaults to `nil` (no expiration).
* `:activity_pub_question` - activity pub routes (question activities). Defaults to `30_000` (30 seconds). * `:activity_pub_question` - activity pub routes (question activities). Defaults to `30_000` (30 seconds).
## :hackney_pools ## HTTP client
### :http
* `proxy_url`: an upstream proxy to fetch posts and/or media with, (default: `nil`)
* `send_user_agent`: should we include a user agent with HTTP requests? (default: `true`)
* `user_agent`: what user agent should we use? (default: `:default`), must be string or `:default`
* `adapter`: array of hackney options
### :hackney_pools
Advanced. Tweaks Hackney (http client) connections pools. Advanced. Tweaks Hackney (http client) connections pools.

View file

@ -17,8 +17,14 @@ def named_version, do: @name <> " " <> @version
def repository, do: @repository def repository, do: @repository
def user_agent do def user_agent do
case Pleroma.Config.get([:http, :user_agent], :default) do
:default ->
info = "#{Pleroma.Web.base_url()} <#{Pleroma.Config.get([:instance, :email], "")}>" info = "#{Pleroma.Web.base_url()} <#{Pleroma.Config.get([:instance, :email], "")}>"
named_version() <> "; " <> info named_version() <> "; " <> info
custom ->
custom
end
end end
# See http://elixir-lang.org/docs/stable/elixir/Application.html # See http://elixir-lang.org/docs/stable/elixir/Application.html

View file

@ -16,11 +16,21 @@ test "don't send pleroma user agent" do
test "send pleroma user agent" do test "send pleroma user agent" do
Pleroma.Config.put([:http, :send_user_agent], true) Pleroma.Config.put([:http, :send_user_agent], true)
Pleroma.Config.put([:http, :user_agent], :default)
assert RequestBuilder.headers(%{}, []) == %{ assert RequestBuilder.headers(%{}, []) == %{
headers: [{"User-Agent", Pleroma.Application.user_agent()}] headers: [{"User-Agent", Pleroma.Application.user_agent()}]
} }
end end
test "send custom user agent" do
Pleroma.Config.put([:http, :send_user_agent], true)
Pleroma.Config.put([:http, :user_agent], "totally-not-pleroma")
assert RequestBuilder.headers(%{}, []) == %{
headers: [{"User-Agent", "totally-not-pleroma"}]
}
end
end end
describe "add_optional_params/3" do describe "add_optional_params/3" do