about summary refs log tree commit diff
path: root/app/helpers
diff options
context:
space:
mode:
authorEugen Rochko <eugen@zeonfederated.com>2020-05-10 11:41:43 +0200
committerGitHub <noreply@github.com>2020-05-10 11:41:43 +0200
commit4b766f984689311523b89e1b68d2a11dff3fc396 (patch)
treea3be769d6f45f35ed6ac068112e2cafe4603c017 /app/helpers
parent4a2ea2e51b22558bf62216b6be932a5d64014164 (diff)
Refactor monkey-patching of Goldfinger (#12561)
Diffstat (limited to 'app/helpers')
-rw-r--r--app/helpers/webfinger_helper.rb19
1 files changed, 19 insertions, 0 deletions
diff --git a/app/helpers/webfinger_helper.rb b/app/helpers/webfinger_helper.rb
new file mode 100644
index 000000000..70c493210
--- /dev/null
+++ b/app/helpers/webfinger_helper.rb
@@ -0,0 +1,19 @@
+# frozen_string_literal: true
+
+module WebfingerHelper
+  def webfinger!(uri)
+    hidden_service_uri = /\.(onion|i2p)(:\d+)?$/.match(uri)
+
+    raise Mastodon::HostValidationError, 'Instance does not support hidden service connections' if !Rails.configuration.x.access_to_hidden_service && hidden_service_uri
+
+    opts = {
+      ssl: !hidden_service_uri,
+
+      headers: {
+        'User-Agent': Mastodon::Version.user_agent,
+      },
+    }
+
+    Goldfinger::Client.new(uri, opts.merge(Rails.configuration.x.http_client_proxy)).finger
+  end
+end