Class: PuppetLibrary::Http::Url

Inherits:
Object
  • Object
show all
Defined in:
lib/puppet_library/http/url.rb

Class Method Summary collapse

Class Method Details

.normalize(uri_string) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/puppet_library/http/url.rb', line 22

def self.normalize(uri_string)
    begin
        url = URI.parse(uri_string)
    rescue URI::InvalidURIError => e
        raise PuppetLibrary::ExpectedError, "Invalid URL '#{uri_string}': #{e.message}"
    end
    if url.scheme
        raise PuppetLibrary::ExpectedError, "Invalid URL '#{uri_string}': unsupported protocol '#{url.scheme}'" unless url.scheme =~ /^https?$/
    else
        uri_string = "http://#{uri_string}"
    end
    uri_string.sub /\/$/, ""
end