File tree Expand file tree Collapse file tree 4 files changed +54
-6
lines changed
Expand file tree Collapse file tree 4 files changed +54
-6
lines changed Original file line number Diff line number Diff line change @@ -69,13 +69,15 @@ def ready?
6969 #
7070 # @parameter error [Exception] Optional error that occurred during processing.
7171 def close ( error = nil )
72- if @body and @body . respond_to? ( :close )
73- @body . close
74- end
75-
76- @body = nil
7772 @chunks = nil
7873
74+ if body = @body
75+ @body = nil
76+ if body . respond_to? ( :close )
77+ body . close
78+ end
79+ end
80+
7981 super
8082 end
8183
Original file line number Diff line number Diff line change 88module Protocol
99 module Rack
1010 module Body
11- Streaming = ::Protocol ::HTTP ::Body ::Streamable ::ResponseBody
11+ class Streaming < ::Protocol ::HTTP ::Body ::Streamable ::ResponseBody
12+ def initialize ( body , input = nil )
13+ @body = body
14+
15+ super
16+ end
17+
18+ def close ( error = nil )
19+ if body = @body
20+ @body = nil
21+ if body . respond_to? ( :close )
22+ body . close
23+ end
24+ end
25+
26+ super
27+ end
28+ end
1229 end
1330 end
1431end
Original file line number Diff line number Diff line change 11# Releases
22
3+ ## Unreleased
4+
5+ - Fix missing ` body#close ` for streaming bodies.
6+
37## v0.21.0
48
59 - For the purpose of constructing the rack request environment, trailers are ignored.
Original file line number Diff line number Diff line change 5050 expect ( body . read ) . to be == "Hello"
5151 end
5252 end
53+
54+ with "#close" do
55+ it "closes the wrapped body if it responds to close" do
56+ close_called = false
57+ wrapped_body = Object . new
58+ wrapped_body . define_singleton_method ( :close ) do
59+ close_called = true
60+ end
61+ wrapped_body . define_singleton_method ( :call ) do |stream |
62+ stream . write ( "Hello" )
63+ end
64+
65+ body = subject . new ( wrapped_body )
66+ body . close
67+
68+ expect ( close_called ) . to be == true
69+ end
70+
71+ it "does not fail if wrapped body does not respond to close" do
72+ wrapped_body = proc { |stream | stream . write ( "Hello" ) }
73+
74+ body = subject . new ( wrapped_body )
75+ body . close
76+ end
77+ end
5378end
You can’t perform that action at this time.
0 commit comments