File tree Expand file tree Collapse file tree 2 files changed +16
-10
lines changed
Expand file tree Collapse file tree 2 files changed +16
-10
lines changed Original file line number Diff line number Diff line change @@ -259,16 +259,6 @@ def streaming_response(status_code = 200, headers ={})
259259[ status_code , headers , Goliath ::Response ::STREAMING ]
260260end
261261
262- def set_event_handler! ( env )
263- if self . class . maps?
264- response = self . class . router . recognize ( env )
265- if response = self . class . router . recognize ( env ) and response . respond_to? ( :path ) and response . 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)
288278def chunked_streaming_response ( status_code = 200 , headers = { } )
289279streaming_response ( status_code , headers . merge ( Goliath ::Response ::CHUNKED_STREAM_HEADERS ) )
290280end
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+ def set_event_handler! ( env )
287+ if self . class . maps?
288+ response = self . class . router . recognize ( env )
289+ if response = self . class . router . recognize ( env ) and response . respond_to? ( :path ) and response . 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+
291296end
292297end
Original file line number Diff line number Diff line change @@ -34,6 +34,7 @@ def post_init
3434r = Goliath ::Request . new ( @app , self , env )
3535r . parse_header ( h , @parser ) do
3636@api . set_event_handler! ( env )
37+
3738env [ ASYNC_HEADERS ] = env . event_handler . method ( :on_headers ) if env . event_handler . respond_to? :on_headers
3839env [ ASYNC_BODY ] = env . event_handler . method ( :on_body ) if env . event_handler . respond_to? :on_body
3940env [ ASYNC_CLOSE ] = env . event_handler . method ( :on_close ) if env . event_handler . respond_to? :on_close
You can’t perform that action at this time.
0 commit comments