Skip to content

Commit

Permalink
Initial idea.
Browse files Browse the repository at this point in the history
  • Loading branch information
ioquatix committed Sep 17, 2024
1 parent 082cc58 commit ddcb2df
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/protocol/http/body/buffered.rb
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,10 @@ def read
end
end

def discard
clear
end

def write(chunk)
@chunks << chunk
end
Expand Down
6 changes: 6 additions & 0 deletions lib/protocol/http/body/readable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,12 @@ def finish
Buffered.read(self)
end

def discard
while chunk = self.read
chunk.clear
end
end

def as_json(...)
{
class: self.class.name,
Expand Down
8 changes: 8 additions & 0 deletions lib/protocol/http/body/reader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,14 @@ def finish
end
end

# Discard the body as efficiently as possible.
def discard
if body = @body
@body = nil
body.discard
end
end

# Buffer the entire request/response body.
# @returns [Reader] itself.
def buffered!
Expand Down
4 changes: 4 additions & 0 deletions lib/protocol/http/body/wrapper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ def read
@body.read
end

def discard
@body.discard
end

def as_json(...)
{
class: self.class.name,
Expand Down

0 comments on commit ddcb2df

Please sign in to comment.