Skip to content

Commit b18a246

Browse files
committed
More test coverage / compatibility.
1 parent 4e462fb commit b18a246

File tree

5 files changed

+19
-6
lines changed

5 files changed

+19
-6
lines changed

lib/protocol/http/body/file.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ def stream?
7373
end
7474

7575
def call(stream)
76-
IO.copy_stream(@file, stream)
76+
IO.copy_stream(@file, stream, @remaining)
7777
end
7878

7979
def join

lib/protocol/http/body/readable.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,10 @@ def join
9494
end
9595
end
9696

97+
def stream?
98+
false
99+
end
100+
97101
# Write the body to the given stream.
98102
#
99103
# In some cases, the stream may also be readable, such as when hijacking an HTTP/1 connection. In that case, it may be acceptable to read and write to the stream directly.
@@ -123,6 +127,7 @@ def as_json(...)
123127
{
124128
class: self.class.name,
125129
length: self.length,
130+
stream: self.stream?,
126131
ready: self.ready?,
127132
empty: self.empty?
128133
}

lib/protocol/http/body/wrapper.rb

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,6 @@ def rewindable?
5050
@body.rewindable?
5151
end
5252

53-
def stream?
54-
# Most wrappers are not streamable by default.
55-
false
56-
end
57-
5853
def length
5954
@body.length
6055
end

test/protocol/http/body/file.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,5 +85,17 @@
8585

8686
expect(output.string).to be == "Hello World"
8787
end
88+
89+
with "/dev/zero" do
90+
it "can stream partial output" do
91+
skip unless File.exist?('/dev/zero')
92+
93+
body = subject.open('/dev/zero', 0...10)
94+
95+
body.call(output)
96+
97+
expect(output.string).to be == "\x00" * 10
98+
end
99+
end
88100
end
89101
end

test/protocol/http/body/readable.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@
6363
expect(body.as_json).to have_keys(
6464
class: be == subject.name,
6565
length: be_nil,
66+
stream: be == false,
6667
ready: be == false,
6768
empty: be == false,
6869
)

0 commit comments

Comments
 (0)