updating tesla

This commit is contained in:
Alex S 2019-08-15 20:43:15 +03:00 committed by Ariadne Conill
parent b5e35dfaa2
commit d53514d111
4 changed files with 33 additions and 5 deletions

View File

@ -67,10 +67,13 @@ defmodule Pleroma.HTTP do
options
conn ->
%{host: host, port: port} = URI.parse(url)
adapter_opts =
Keyword.get(options, :adapter, [])
|> Keyword.put(:conn, conn)
|> Keyword.put(:close_conn, false)
|> Keyword.put(:original, "#{host}:#{port}")
Keyword.put(options, :adapter, adapter_opts)
end

10
mix.exs
View File

@ -111,10 +111,12 @@ defmodule Pleroma.Mixfile do
{:calendar, "~> 0.17.4"},
{:cachex, "~> 3.0.2"},
{:poison, "~> 3.0", override: true},
{:tesla,
github: "alex-strizhakov/tesla",
ref: "82dd3ace650b93d6699cf379b1a238d891f45cfb",
override: true},
{
:tesla,
github: "alex-strizhakov/tesla",
ref: "33ba3bbd44d6fddd6558aaf4d9768c8de5f279b8",
override: true
},
{:cowlib, "~> 2.6.0", override: true},
{:gun, "~> 1.3"},
{:jason, "~> 1.0"},

View File

@ -85,7 +85,7 @@
"swoosh": {:hex, :swoosh, "0.23.2", "7dda95ff0bf54a2298328d6899c74dae1223777b43563ccebebb4b5d2b61df38", [:mix], [{:cowboy, "~> 1.0.1 or ~> 1.1 or ~> 2.4", [hex: :cowboy, repo: "hexpm", optional: true]}, {:gen_smtp, "~> 0.13", [hex: :gen_smtp, repo: "hexpm", optional: true]}, {:hackney, "~> 1.9", [hex: :hackney, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}, {:mail, "~> 0.2", [hex: :mail, repo: "hexpm", optional: true]}, {:mime, "~> 1.1", [hex: :mime, repo: "hexpm", optional: false]}, {:plug_cowboy, ">= 1.0.0", [hex: :plug_cowboy, repo: "hexpm", optional: true]}], "hexpm"},
"syslog": {:git, "https://github.com/Vagabond/erlang-syslog.git", "4a6c6f2c996483e86c1320e9553f91d337bcb6aa", [tag: "1.0.5"]},
"telemetry": {:hex, :telemetry, "0.4.0", "8339bee3fa8b91cb84d14c2935f8ecf399ccd87301ad6da6b71c09553834b2ab", [:rebar3], [], "hexpm"},
"tesla": {:git, "https://github.com/alex-strizhakov/tesla.git", "82dd3ace650b93d6699cf379b1a238d891f45cfb", [ref: "82dd3ace650b93d6699cf379b1a238d891f45cfb"]},
"tesla": {:git, "https://github.com/alex-strizhakov/tesla.git", "33ba3bbd44d6fddd6558aaf4d9768c8de5f279b8", [ref: "33ba3bbd44d6fddd6558aaf4d9768c8de5f279b8"]},
"timex": {:hex, :timex, "3.6.1", "efdf56d0e67a6b956cc57774353b0329c8ab7726766a11547e529357ffdc1d56", [:mix], [{:combine, "~> 0.10", [hex: :combine, repo: "hexpm", optional: false]}, {:gettext, "~> 0.10", [hex: :gettext, repo: "hexpm", optional: false]}, {:tzdata, "~> 0.1.8 or ~> 0.5 or ~> 1.0.0", [hex: :tzdata, repo: "hexpm", optional: false]}], "hexpm"},
"trailing_format_plug": {:hex, :trailing_format_plug, "0.0.7", "64b877f912cf7273bed03379936df39894149e35137ac9509117e59866e10e45", [:mix], [{:plug, "> 0.12.0", [hex: :plug, repo: "hexpm", optional: false]}], "hexpm"},
"tzdata": {:hex, :tzdata, "0.5.21", "8cbf3607fcce69636c672d5be2bbb08687fe26639a62bdcc283d267277db7cf0", [:mix], [{:hackney, "~> 1.0", [hex: :hackney, repo: "hexpm", optional: false]}], "hexpm"},

View File

@ -361,5 +361,28 @@ defmodule Pleroma.ReverseProxyTest do
Pleroma.Config.put([Pleroma.Gun.API], api)
end)
end
test "tesla client with gun client follow redirects", %{conn: conn} do
client = Pleroma.Config.get([Pleroma.ReverseProxy.Client])
Pleroma.Config.put([Pleroma.ReverseProxy.Client], Pleroma.ReverseProxy.Client.Tesla)
adapter = Application.get_env(:tesla, :adapter)
Application.put_env(:tesla, :adapter, Tesla.Adapter.Gun)
api = Pleroma.Config.get([Pleroma.Gun.API])
Pleroma.Config.put([Pleroma.Gun.API], :gun)
{:ok, _} = Pleroma.Gun.Connections.start_link(Pleroma.Gun.Connections)
conn = ReverseProxy.call(conn, "https://httpbin.org/redirect/7")
assert byte_size(conn.resp_body) == 10
assert conn.state == :chunked
assert conn.status == 200
on_exit(fn ->
Pleroma.Config.put([Pleroma.ReverseProxy.Client], client)
Application.put_env(:tesla, :adapter, adapter)
Pleroma.Config.put([Pleroma.Gun.API], api)
end)
end
end
end