1
0

http_client_proxy.rb 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. # frozen_string_literal: true
  2. Rails.application.configure do
  3. config.x.http_client_proxy = {}
  4. if ENV['http_proxy'].present?
  5. proxy = URI.parse(ENV['http_proxy'])
  6. raise "Unsupported proxy type: #{proxy.scheme}" unless %w(http https).include? proxy.scheme
  7. raise "No proxy host" unless proxy.host
  8. host = proxy.host
  9. host = host[1...-1] if host[0] == '[' # for IPv6 address
  10. config.x.http_client_proxy[:proxy] = {
  11. proxy_address: host,
  12. proxy_port: proxy.port,
  13. proxy_username: proxy.user,
  14. proxy_password: proxy.password,
  15. }.compact
  16. end
  17. if ENV['http_hidden_proxy'].present?
  18. proxy = URI.parse(ENV['http_hidden_proxy'])
  19. raise "Unsupported proxy type: #{proxy.scheme}" unless %w(http https).include? proxy.scheme
  20. raise "No proxy host" unless proxy.host
  21. host = proxy.host
  22. host = host[1...-1] if host[0] == '[' # for IPv6 address
  23. config.x.http_client_hidden_proxy[:proxy] = {
  24. proxy_address: host,
  25. proxy_port: proxy.port,
  26. proxy_username: proxy.user,
  27. proxy_password: proxy.password,
  28. }.compact
  29. end
  30. config.x.access_to_hidden_service = ENV['ALLOW_ACCESS_TO_HIDDEN_SERVICE'] == 'true'
  31. end