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.

38 lines
1.1 KiB

  1. # frozen_string_literal: true
  2. # Monkey-patch on monkey-patch.
  3. # Because it conflicts with the request.rb patch.
  4. class HTTP::Timeout::PerOperationOriginal < HTTP::Timeout::PerOperation
  5. def connect(socket_class, host, port, nodelay = false)
  6. ::Timeout.timeout(@connect_timeout, HTTP::TimeoutError) do
  7. @socket = socket_class.open(host, port)
  8. @socket.setsockopt(Socket::IPPROTO_TCP, Socket::TCP_NODELAY, 1) if nodelay
  9. end
  10. end
  11. end
  12. module WebfingerHelper
  13. def webfinger!(uri)
  14. hidden_service_uri = /\.(onion|i2p)(:\d+)?$/.match(uri)
  15. raise Mastodon::HostValidationError, 'Instance does not support hidden service connections' if !Rails.configuration.x.access_to_hidden_service && hidden_service_uri
  16. opts = {
  17. ssl: !hidden_service_uri,
  18. headers: {
  19. 'User-Agent': Mastodon::Version.user_agent,
  20. },
  21. timeout_class: HTTP::Timeout::PerOperationOriginal,
  22. timeout_options: {
  23. write_timeout: 10,
  24. connect_timeout: 5,
  25. read_timeout: 10,
  26. },
  27. }
  28. Goldfinger::Client.new(uri, opts.merge(Rails.configuration.x.http_client_proxy)).finger
  29. end
  30. end