Class: SimpleServer

Inherits:
Sinatra::Base
  • Object
show all
Defined in:
lib/simple-server.rb

Instance Method Summary collapse

Instance Method Details

#parse_request(request) ⇒ Object



25
26
27
28
29
30
31
32
33
34
# File 'lib/simple-server.rb', line 25

def parse_request(request)
  begin
    uri = Addressable::URI.parse(request.url)
  rescue Addressable::URI::InvalidURIError => e
    logger.info "#{uri}: invalid URI (#{e.message}): denying"
    halt 400, 'invalid URI'
  end
  uri.host = request.host
  uri
end

#path_for_uri(uri) ⇒ Object



17
18
19
20
21
22
23
# File 'lib/simple-server.rb', line 17

def path_for_uri(uri)
  path = Path.new(settings.root)
  path /= (uri.normalized_host ||= settings.default_host).sub(/^(www|web|test|dev).*?\./, '') if settings.multihosting
  path /= Path.new(Addressable::URI.unencode_component(uri.normalized_path)).relative_to('/')
  path /= 'index.html' if uri.normalized_path.end_with?('/')
  path
end