Method: Unify::HTTP#call

Defined in:
lib/unify/http.rb

#call(env) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/unify/http.rb', line 36

def call(env)
  if @routes[env['REQUEST_METHOD']]
    for route in @routes[env['REQUEST_METHOD']]
      if match = route[0].match(env['PATH_INFO'])
        @response = Rack::Response.new
        unless @response.write(route[1].call(*match.captures))
          @response = nil
        end
        break
      end
    end
  end
  unless @response
    @response = Rack::Response.new('Page Not Found')
    @response.status = 404
  end
  @response.finish
end