class Protocol::HTTP::Reference

def expand_path(base, relative, pop = true)

Parameters:
  • pop (Boolean) -- whether to remove the last path component of the base path, to conform to URI merging behaviour, as defined by RFC2396.
def expand_path(base, relative, pop = true)
	if relative.start_with? '/'
		return relative
	else
		path = split(base)
		
		# RFC2396 Section 5.2:
		# 6) a) All but the last segment of the base URI's path component is
		# copied to the buffer.  In other words, any characters after the
		# last (right-most) slash character, if any, are excluded.
		path.pop if pop or path.last == ''
		
		parts = split(relative)
		
		parts.each do |part|
			if part == '..'
				path.pop
			elsif part == '.'
				# Do nothing.
			else
				path << part
			end
		end
		
		return path.join('/')
	end
end