Skip to content

Commit 5853a65

Browse files
committed
document set_event_handler
1 parent 8f7f6bc commit 5853a65

File tree

2 files changed

+16
-10
lines changed

2 files changed

+16
-10
lines changed

‎lib/goliath/api.rb‎

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -259,16 +259,6 @@ def streaming_response(status_code = 200, headers ={})
259259
[status_code,headers,Goliath::Response::STREAMING]
260260
end
261261

262-
defset_event_handler!(env)
263-
ifself.class.maps?
264-
response=self.class.router.recognize(env)
265-
ifresponse=self.class.router.recognize(env)andresponse.respond_to?(:path)andresponse.path.route.api_class
266-
env.event_handler=response.path.route.api_class.new
267-
end
268-
end
269-
env.event_handler ||= self
270-
end
271-
272262
# Helper method for chunked transfer streaming response apis
273263
#
274264
# Chunked transfer streaming is transparent to all clients (it's just as
@@ -288,5 +278,20 @@ def set_event_handler!(env)
288278
defchunked_streaming_response(status_code=200,headers={})
289279
streaming_response(status_code,headers.merge(Goliath::Response::CHUNKED_STREAM_HEADERS))
290280
end
281+
282+
# Helper method to initialize the approriate API handler
283+
#
284+
# Called by the parser once headers are available to detect
285+
# which API class should be handling the incoming request
286+
defset_event_handler!(env)
287+
ifself.class.maps?
288+
response=self.class.router.recognize(env)
289+
ifresponse=self.class.router.recognize(env)andresponse.respond_to?(:path)andresponse.path.route.api_class
290+
env.event_handler=response.path.route.api_class.new
291+
end
292+
end
293+
env.event_handler ||= self
294+
end
295+
291296
end
292297
end

‎lib/goliath/connection.rb‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ def post_init
3434
r=Goliath::Request.new(@app,self,env)
3535
r.parse_header(h,@parser)do
3636
@api.set_event_handler!(env)
37+
3738
env[ASYNC_HEADERS]=env.event_handler.method(:on_headers)ifenv.event_handler.respond_to?:on_headers
3839
env[ASYNC_BODY]=env.event_handler.method(:on_body)ifenv.event_handler.respond_to?:on_body
3940
env[ASYNC_CLOSE]=env.event_handler.method(:on_close)ifenv.event_handler.respond_to?:on_close

0 commit comments

Comments
(0)