File tree Expand file tree Collapse file tree 1 file changed +30
-3
lines changed
actionpack/lib/action_controller/metal Expand file tree Collapse file tree 1 file changed +30
-3
lines changed Original file line number Diff line number Diff line change 1
1
# frozen_string_literal: true
2
2
3
- require "rack/chunked"
4
-
5
3
module ActionController # :nodoc:
6
4
# = Action Controller \Streaming
7
5
#
@@ -208,6 +206,35 @@ module ActionController # :nodoc:
208
206
# * https://www.phusionpassenger.com/docs/references/config_reference/nginx/#passenger_buffer_response
209
207
#
210
208
module Streaming
209
+ class Body # :nodoc:
210
+ TERM = "\r \n "
211
+ TAIL = "0#{ TERM } "
212
+
213
+ # Store the response body to be chunked.
214
+ def initialize ( body )
215
+ @body = body
216
+ end
217
+
218
+ # For each element yielded by the response body, yield
219
+ # the element in chunked encoding.
220
+ def each ( &block )
221
+ term = TERM
222
+ @body . each do |chunk |
223
+ size = chunk . bytesize
224
+ next if size == 0
225
+
226
+ yield [ size . to_s ( 16 ) , term , chunk . b , term ] . join
227
+ end
228
+ yield TAIL
229
+ yield term
230
+ end
231
+
232
+ # Close the response body if the response body supports it.
233
+ def close
234
+ @body . close if @body . respond_to? ( :close )
235
+ end
236
+ end
237
+
211
238
private
212
239
# Set proper cache control and transfer encoding when streaming
213
240
def _process_options ( options )
@@ -226,7 +253,7 @@ def _process_options(options)
226
253
# Call render_body if we are streaming instead of usual +render+.
227
254
def _render_template ( options )
228
255
if options . delete ( :stream )
229
- Rack :: Chunked :: Body . new view_renderer . render_body ( view_context , options )
256
+ Body . new view_renderer . render_body ( view_context , options )
230
257
else
231
258
super
232
259
end
You can’t perform that action at this time.
0 commit comments