Skip to content

Commit af68c31

Browse files
committed
Remove dependency on deprecated Rack::Chunked
Import the used Rack::Chunked::Body as private AC::Streaming::Body class and use it instead.
1 parent d4983a9 commit af68c31

File tree

1 file changed

+30
-3
lines changed

1 file changed

+30
-3
lines changed

actionpack/lib/action_controller/metal/streaming.rb

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
# frozen_string_literal: true
22

3-
require "rack/chunked"
4-
53
module ActionController # :nodoc:
64
# = Action Controller \Streaming
75
#
@@ -208,6 +206,35 @@ module ActionController # :nodoc:
208206
# * https://www.phusionpassenger.com/docs/references/config_reference/nginx/#passenger_buffer_response
209207
#
210208
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+
211238
private
212239
# Set proper cache control and transfer encoding when streaming
213240
def _process_options(options)
@@ -226,7 +253,7 @@ def _process_options(options)
226253
# Call render_body if we are streaming instead of usual +render+.
227254
def _render_template(options)
228255
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)
230257
else
231258
super
232259
end

0 commit comments

Comments
 (0)