Skip to content

Commit

Permalink
More test coverage / compatibility.
Browse files Browse the repository at this point in the history
  • Loading branch information
ioquatix committed Sep 5, 2024
1 parent 4e462fb commit b18a246
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 6 deletions.
2 changes: 1 addition & 1 deletion lib/protocol/http/body/file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def stream?
end

def call(stream)
IO.copy_stream(@file, stream)
IO.copy_stream(@file, stream, @remaining)
end

def join
Expand Down
5 changes: 5 additions & 0 deletions lib/protocol/http/body/readable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,10 @@ def join
end
end

def stream?
false
end

# Write the body to the given stream.
#
# 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.
Expand Down Expand Up @@ -123,6 +127,7 @@ def as_json(...)
{
class: self.class.name,
length: self.length,
stream: self.stream?,
ready: self.ready?,
empty: self.empty?
}
Expand Down
5 changes: 0 additions & 5 deletions lib/protocol/http/body/wrapper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,6 @@ def rewindable?
@body.rewindable?
end

def stream?
# Most wrappers are not streamable by default.
false
end

def length
@body.length
end
Expand Down
12 changes: 12 additions & 0 deletions test/protocol/http/body/file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -85,5 +85,17 @@

expect(output.string).to be == "Hello World"
end

with "/dev/zero" do
it "can stream partial output" do
skip unless File.exist?('/dev/zero')

body = subject.open('/dev/zero', 0...10)

body.call(output)

expect(output.string).to be == "\x00" * 10
end
end
end
end
1 change: 1 addition & 0 deletions test/protocol/http/body/readable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
expect(body.as_json).to have_keys(
class: be == subject.name,
length: be_nil,
stream: be == false,
ready: be == false,
empty: be == false,
)
Expand Down

0 comments on commit b18a246

Please sign in to comment.