class ResponsePreparer
Constants
- SERVER_ROOT
Public Instance Methods
prepare_response(request)
click to toggle source
# File lib/http.rb, line 4 def prepare_response(request) if request.fetch(:path) == "/" respond_with(SERVER_ROOT + "index.html") else respond_with(SERVER_ROOT + request.fetch(:path)) end end
respond_with(path)
click to toggle source
# File lib/http.rb, line 12 def respond_with(path) if File.exists?(path) send_ok_response(File.binread(path)) else send_file_not_found end end
send_file_not_found()
click to toggle source
# File lib/http.rb, line 24 def send_file_not_found Response.new(code: 404) end
send_ok_response(data)
click to toggle source
# File lib/http.rb, line 20 def send_ok_response(data) Response.new(code: 200, data: data) end