Skip to content

Commit 942f63b

Browse files
Expose Body::Writable#count.
1 parent a5ca5d2 commit 942f63b

File tree

3 files changed

+46
-0
lines changed

3 files changed

+46
-0
lines changed

lib/protocol/http/body/writable.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ def initialize(length = nil, queue: Thread::Queue.new)
2828
# @attribute [Integer] The length of the response body if known.
2929
attr :length
3030

31+
# @attribute [Integer] The number of chunks written to the body.
32+
attr :count
33+
3134
# Stop generating output; cause the next call to write to fail with the given error. Does not prevent existing chunks from being read. In other words, this indicates both that no more data will be or should be written to the body.
3235
#
3336
# @parameter error [Exception] The error that caused this body to be closed, if any. Will be raised on the next call to {read}.

releases.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Releases
22

3+
## Unreleased
4+
5+
- Expose `Protocol::HTTP::Body::Writable#count` attribute to provide access to the number of chunks written to the body.
6+
37
## v0.59.0
48

59
- Introduce `Protocol::HTTP::Middleware.load` method for loading middleware applications from files.

test/protocol/http/body/writable.rb

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,45 @@
1818
end
1919
end
2020

21+
with "#count" do
22+
it "should be zero by default" do
23+
expect(body.count).to be == 0
24+
end
25+
26+
it "should increment when chunks are written" do
27+
expect(body.count).to be == 0
28+
29+
body.write("Hello")
30+
expect(body.count).to be == 1
31+
32+
body.write("World")
33+
expect(body.count).to be == 2
34+
35+
body.write("")
36+
expect(body.count).to be == 3
37+
end
38+
39+
it "should not increment when reading chunks" do
40+
body.write("Hello")
41+
body.write("World")
42+
43+
expect(body.count).to be == 2
44+
45+
body.read
46+
body.read
47+
48+
expect(body.count).to be == 2
49+
end
50+
51+
it "should not change when body is closed" do
52+
body.write("Hello")
53+
expect(body.count).to be == 1
54+
55+
body.close
56+
expect(body.count).to be == 1
57+
end
58+
end
59+
2160
with "#closed?" do
2261
it "should not be closed by default" do
2362
expect(body).not.to be(:closed?)

0 commit comments

Comments
 (0)