url_information.rb 590 B

1234567891011121314151617181920212223242526
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. class UrlInformation < SimpleDelegator
  3. class UrlInformation::Error < StandardError; end
  4. DEFAULT_SCHEMA_PORTS = [['http', 80], ['https', 443]].freeze
  5. def initialize(url)
  6. uri = URI(url)
  7. raise UrlInformation::Error if %w[http https].exclude?(uri.scheme) || uri.host.blank?
  8. super(uri)
  9. rescue
  10. raise UrlInformation::Error
  11. end
  12. def fqdn
  13. @fqdn ||= begin
  14. if DEFAULT_SCHEMA_PORTS.include? [scheme, port]
  15. host
  16. else
  17. "#{host}:#{port}"
  18. end
  19. end
  20. end
  21. end