lib/angelo/server.rb in angelo-0.2.1 vs lib/angelo/server.rb in angelo-0.2.2
- old
+ new
@@ -16,14 +16,19 @@
super host, port, &method(:on_connection)
end
def on_connection connection
# RubyProf.resume
+ responders = []
+
connection.each_request do |request|
meth = request.websocket? ? :websocket : request.method.downcase.to_sym
- dispatch! meth, connection, request
+ responder = dispatch! meth, connection, request
+ responders << responder if responder and responder.respond_to? :on_close
end
+
+ responders.each &:on_close
# RubyProf.pause
end
def self.define_task name, &action
define_method name, &action
@@ -47,12 +52,15 @@
end
def route! meth, connection, request
if @base.routes[meth] and rs = @base.routes[meth][request.path]
responder = rs.dup
+ responder.reset!
responder.base = @base.new responder
responder.connection = connection
responder.request = request
+ responder.handle_request
+ responder
else
Angelo.log connection, request, nil, :not_found
connection.respond :not_found, DEFAULT_RESPONSE_HEADERS, NOT_FOUND
end
end