1
0

http_client_proxy.rb 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839
  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] = {
  10. proxy_address: host,
  11. proxy_port: proxy.port,
  12. proxy_username: proxy.user,
  13. proxy_password: proxy.password,
  14. }.compact
  15. end
  16. if ENV['http_hidden_proxy'].present?
  17. proxy = URI.parse(ENV['http_hidden_proxy'])
  18. raise "Unsupported proxy type: #{proxy.scheme}" unless %w(http https).include? proxy.scheme
  19. raise "No proxy host" unless proxy.host
  20. host = proxy.host
  21. host = host[1...-1] if host[0] == '[' # for IPv6 address
  22. config.x.http_client_hidden_proxy[:proxy] = {
  23. proxy_address: host,
  24. proxy_port: proxy.port,
  25. proxy_username: proxy.user,
  26. proxy_password: proxy.password,
  27. }.compact
  28. end
  29. config.x.access_to_hidden_service = ENV['ALLOW_ACCESS_TO_HIDDEN_SERVICE'] == 'true'
  30. end