class Object

Constants

CONTENT_TYPE_MAPPING
DEFAULT_CONTENT_TYPE
WEB_ROOT

Public Instance Methods

content_type(path) click to toggle source
# File lib/servit.rb, line 15
def content_type(path)
  ext = File.extname(path).split(".").last
  CONTENT_TYPE_MAPPING.fetch(ext, DEFAULT_CONTENT_TYPE)
end
requested_file(request_line) click to toggle source
# File lib/servit.rb, line 20
def requested_file(request_line)
  request_uri = request_line.split(" ")[1]
  path = URI.unescape(URI(request_uri).path)
  
  clean = []

  parts = path.split("/")

  parts.each do |part|
    next if part.empty? || part == '.'
    part == '..' ? clean.pop : clean << part
  end

  File.join(WEB_ROOT, *clean)
end