class Nile::HttpHandler

Public Instance Methods

handle(req, sock) click to toggle source
# File lib/nile/framework.rb, line 29
def handle req, sock
    start = Time.new
    r = Router.instance

    querystring = req[:url].split("?")
    params = {}
    if querystring[1].respond_to? :split
        querystring[1].split("&").each do |param|
            param =~ /(\w+)=*(.*)/
            params[$1] = $2
        end
    end

    route = r.find_route(req[:verb], querystring[0])
    begin
        response = route[:cb].call({:params => params, :req => req})
    rescue Exception => e
        response = [500, {}, ['Internal Server Error: ' + e.message]]
    end

    response[1]['Server'] = "Nile #{Nile::VERSION}"
    response[1]['Content-Length'] = response[2].join("\n").length

    return response
end