From 5ddd15d794bc8f9be3ca073589bab1f92b001cce Mon Sep 17 00:00:00 2001 From: Jeff Becker Date: Sat, 30 Dec 2017 11:35:53 -0500 Subject: [PATCH 1/6] make httppoison use configurable http proxy --- config/config.exs | 5 ++++- lib/pleroma/http/http.ex | 14 ++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 lib/pleroma/http/http.ex diff --git a/config/config.exs b/config/config.exs index 503ce8d64..28335a6d4 100644 --- a/config/config.exs +++ b/config/config.exs @@ -32,7 +32,7 @@ config :pleroma, :websub, Pleroma.Web.Websub config :pleroma, :ostatus, Pleroma.Web.OStatus -config :pleroma, :httpoison, HTTPoison +config :pleroma, :httpoison, Pleroma.HTTP version = with {version, 0} <- System.cmd("git", ["rev-parse", "HEAD"]) do "Pleroma #{String.trim(version)}" @@ -40,6 +40,9 @@ _ -> "Pleroma dev" end +config :pleroma, :http, + proxy_url: "" + config :pleroma, :instance, version: version, name: "Pleroma", diff --git a/lib/pleroma/http/http.ex b/lib/pleroma/http/http.ex new file mode 100644 index 000000000..31135411c --- /dev/null +++ b/lib/pleroma/http/http.ex @@ -0,0 +1,14 @@ + +defmodule Pleroma.HTTP do + use HTTPoison.Base + + def process_request_options(options) do + config = Application.get_env(:pleroma, :http, []) + proxy = Keyword.get(config, :proxy_url, "") + case proxy do + "" -> options + _ -> options ++ [proxy: proxy] + end + end + +end From 658c4754ff2e1ce91f020af193f8c7a9d5ef4df2 Mon Sep 17 00:00:00 2001 From: Jeff Becker Date: Sat, 30 Dec 2017 13:02:51 -0500 Subject: [PATCH 2/6] docs --- README.md | 9 +++++++++ config/config.exs | 1 + 2 files changed, 10 insertions(+) diff --git a/README.md b/README.md index 664b8b475..79ce2d19f 100644 --- a/README.md +++ b/README.md @@ -50,3 +50,12 @@ Logs can be watched by using `journalctl -fu pleroma.service` ### Standalone/run by other means Run `mix phx.server` in repository's root, it will output log into stdout/stderr + +### Using an upstream proxy for federation + +Add the following to your `dev.secret.exs` if you want to proxify all http requests that pleroma makes to an upstream proxy server: + + config :pleroma, :http, + proxy_url: "127.0.0.1:8123" + +This is useful for running pleroma inside Tor or i2p. diff --git a/config/config.exs b/config/config.exs index 28335a6d4..05995085c 100644 --- a/config/config.exs +++ b/config/config.exs @@ -40,6 +40,7 @@ _ -> "Pleroma dev" end +# Configures http settings, upstream proxy etc. config :pleroma, :http, proxy_url: "" From 39854d6c11c11767ff568c6020b0506a9cdde4e4 Mon Sep 17 00:00:00 2001 From: Jeff Becker Date: Sat, 30 Dec 2017 13:04:26 -0500 Subject: [PATCH 3/6] clarify --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 79ce2d19f..da528e1a2 100644 --- a/README.md +++ b/README.md @@ -53,7 +53,7 @@ Run `mix phx.server` in repository's root, it will output log into stdout/stderr ### Using an upstream proxy for federation -Add the following to your `dev.secret.exs` if you want to proxify all http requests that pleroma makes to an upstream proxy server: +Add the following to your `dev.secret.exs` or `prod.secret.exs` if you want to proxify all http requests that pleroma makes to an upstream proxy server: config :pleroma, :http, proxy_url: "127.0.0.1:8123" From 1e185b9301ec85cd2aaeb1faf075aaa86f733373 Mon Sep 17 00:00:00 2001 From: Jeff Becker Date: Sun, 31 Dec 2017 09:25:00 -0500 Subject: [PATCH 4/6] apply proxy settings to media_proxy --- lib/pleroma/web/media_proxy/controller.ex | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/pleroma/web/media_proxy/controller.ex b/lib/pleroma/web/media_proxy/controller.ex index 560a65353..9327e7253 100644 --- a/lib/pleroma/web/media_proxy/controller.ex +++ b/lib/pleroma/web/media_proxy/controller.ex @@ -2,6 +2,8 @@ defmodule Pleroma.Web.MediaProxy.MediaProxyController do use Pleroma.Web, :controller require Logger + @httpoison Application.get_env(:pleroma, :httpoison) + @max_body_length 25 * 1048576 @cache_control %{ @@ -29,7 +31,7 @@ def remote(conn, %{"sig" => sig, "url" => url}) do defp proxy_request(link) do headers = [{"user-agent", "Pleroma/MediaProxy; #{Pleroma.Web.base_url()} <#{Application.get_env(:pleroma, :instance)[:email]}>"}] - options = [:insecure, {:follow_redirect, true}] + options = @httpoison.process_request_options([:insecure, {:follow_redirect, true}]) with \ {:ok, 200, headers, client} <- :hackney.request(:get, link, headers, "", options), headers = Enum.into(headers, Map.new), From 6678fe3217d82da7297215c4de369235e3d4d05d Mon Sep 17 00:00:00 2001 From: eal Date: Tue, 16 Jan 2018 15:48:27 +0200 Subject: [PATCH 5/6] Add a Caddyfile. --- installation/Caddyfile | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 installation/Caddyfile diff --git a/installation/Caddyfile b/installation/Caddyfile new file mode 100644 index 000000000..08d5e6169 --- /dev/null +++ b/installation/Caddyfile @@ -0,0 +1,5 @@ +instance.example.com { # Your instance's domain + proxy / localhost:4000 { + websocket + } +} From 066fe1a697286e38c9e9ef7f2c273c4e7a50ffdc Mon Sep 17 00:00:00 2001 From: Jeff Becker Date: Mon, 29 Jan 2018 10:06:16 -0500 Subject: [PATCH 6/6] use nil instead of empty string --- config/config.exs | 2 +- lib/pleroma/http/http.ex | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/config/config.exs b/config/config.exs index 05995085c..e71d5e5a0 100644 --- a/config/config.exs +++ b/config/config.exs @@ -42,7 +42,7 @@ # Configures http settings, upstream proxy etc. config :pleroma, :http, - proxy_url: "" + proxy_url: nil config :pleroma, :instance, version: version, diff --git a/lib/pleroma/http/http.ex b/lib/pleroma/http/http.ex index 31135411c..8b8a82353 100644 --- a/lib/pleroma/http/http.ex +++ b/lib/pleroma/http/http.ex @@ -4,9 +4,9 @@ defmodule Pleroma.HTTP do def process_request_options(options) do config = Application.get_env(:pleroma, :http, []) - proxy = Keyword.get(config, :proxy_url, "") + proxy = Keyword.get(config, :proxy_url, nil) case proxy do - "" -> options + nil -> options _ -> options ++ [proxy: proxy] end end