module T2Server::Util

Public Class Methods

strip_path_slashes(path) → String click to toggle source

Returns a new String with one leading and one trailing slash removed from the ends of path (if present).

# File lib/t2-server/util.rb, line 66
def self.strip_path_slashes(path)
  path.gsub(%r^\//, "").chomp("/")
end
strip_uri_credentials(uri) → URI, Credentials click to toggle source

Strip user credentials from an address in URI or String format and return a tuple of the URI minus the credentials and a T2Server::Credentials object.

# File lib/t2-server/util.rb, line 42
def self.strip_uri_credentials(uri)
  # we want to use URIs here but strings can be passed in
  unless uri.is_a? URI
    uri = URI.parse(Util.strip_path_slashes(uri))
  end

  creds = nil

  # strip username and password from the URI if present
  if uri.user != nil
    creds = T2Server::HttpBasic.new(uri.user, uri.password)

    uri = URI::HTTP.new(uri.scheme, nil, uri.host, uri.port, nil,
    uri.path, nil, nil, nil);
  end

  [uri, creds]
end