The code powering m.abunchtell.com https://m.abunchtell.com
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.
 
 
 
 

25 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. end
  13. module Goldfinger
  14. def self.finger(uri, opts = {})
  15. to_hidden = /\.(onion|i2p)(:\d+)?$/.match(uri)
  16. raise Mastodon::HostValidationError, 'Instance does not support hidden service connections' if !Rails.configuration.x.access_to_hidden_service && to_hidden
  17. opts = { ssl: !to_hidden, headers: {} }.merge(Rails.configuration.x.http_client_proxy).merge(opts)
  18. opts[:headers]['User-Agent'] ||= Mastodon::Version.user_agent
  19. Goldfinger::Client.new(uri, opts).finger
  20. end
  21. end