You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

24 lines
1.1 KiB

  1. Rails.application.configure do
  2. config.x.http_client_proxy = {}
  3. if ENV['http_proxy'].present?
  4. proxy = URI.parse(ENV['http_proxy'])
  5. raise "Unsupported proxy type: #{proxy.scheme}" unless %w(http https).include? proxy.scheme
  6. raise "No proxy host" unless proxy.host
  7. host = proxy.host
  8. host = host[1...-1] if host[0] == '[' #for IPv6 address
  9. config.x.http_client_proxy[:proxy] = { proxy_address: host, proxy_port: proxy.port, proxy_username: proxy.user, proxy_password: proxy.password }.compact
  10. end
  11. config.x.access_to_hidden_service = ENV['ALLOW_ACCESS_TO_HIDDEN_SERVICE'] == 'true'
  12. config.x.hidden_service_via_transparent_proxy = ENV['HIDDEN_SERVICE_VIA_TRANSPARENT_PROXY'] == 'true'
  13. end
  14. module Goldfinger
  15. def self.finger(uri, opts = {})
  16. to_hidden = /\.(onion|i2p)(:\d+)?$/.match(uri)
  17. raise Mastodon::HostValidationError, 'Instance does not support hidden service connections' if !Rails.configuration.x.access_to_hidden_service && to_hidden
  18. opts = opts.merge(Rails.configuration.x.http_client_proxy).merge(ssl: !to_hidden)
  19. Goldfinger::Client.new(uri, opts).finger
  20. end
  21. end