forked from AkkomaGang/akkoma
add ability to set a custom user-agent string
This commit is contained in:
parent
34cdbcbb64
commit
d3656c2725
4 changed files with 26 additions and 2 deletions
|
@ -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
|
||||||
|
|
|
@ -74,6 +74,13 @@ You shouldn't edit the base config directly to avoid breakages and merge conflic
|
||||||
|
|
||||||
* `dynamic_configuration`: Allow transferring configuration to DB with the subsequent customization from Admin api.
|
* `dynamic_configuration`: Allow transferring configuration to DB with the subsequent customization from Admin api.
|
||||||
|
|
||||||
|
## :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
|
||||||
|
|
||||||
## Federation
|
## Federation
|
||||||
### MRF policies
|
### MRF policies
|
||||||
|
|
||||||
|
|
|
@ -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
|
||||||
info = "#{Pleroma.Web.base_url()} <#{Pleroma.Config.get([:instance, :email], "")}>"
|
case Pleroma.Config.get([:http, :user_agent], :default) do
|
||||||
named_version() <> "; " <> info
|
:default ->
|
||||||
|
info = "#{Pleroma.Web.base_url()} <#{Pleroma.Config.get([:instance, :email], "")}>"
|
||||||
|
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
|
||||||
|
|
|
@ -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
|
||||||
|
|
Loading…
Reference in a new issue