Class: Nile::HttpHandler

Inherits:
Object
  • Object
show all
Defined in:
lib/nile/framework.rb

Instance Method Summary collapse

Instance Method Details

#handle(req, sock) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/nile/framework.rb', line 30

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 0.1'
    response[1]['Content-Length'] = response[2].join("\n").length

    return response
end