Skip to content

Commit fa1fe2b

Browse files
committed
Initial idea.
1 parent 6b9f0a8 commit fa1fe2b

File tree

4 files changed

+22
-0
lines changed

4 files changed

+22
-0
lines changed

lib/protocol/http/body/buffered.rb

+4
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,10 @@ def read
9090
end
9191
end
9292

93+
def discard
94+
clear
95+
end
96+
9397
def write(chunk)
9498
@chunks << chunk
9599
end

lib/protocol/http/body/readable.rb

+6
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,12 @@ def finish
133133
Buffered.read(self)
134134
end
135135

136+
def discard
137+
while chunk = self.read
138+
chunk.clear
139+
end
140+
end
141+
136142
def as_json(...)
137143
{
138144
class: self.class.name,

lib/protocol/http/body/reader.rb

+8
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,14 @@ def finish
4040
end
4141
end
4242

43+
# Discard the body as efficiently as possible.
44+
def discard
45+
if body = @body
46+
@body = nil
47+
body.discard
48+
end
49+
end
50+
4351
# Buffer the entire request/response body.
4452
# @returns [Reader] itself.
4553
def buffered!

lib/protocol/http/body/wrapper.rb

+4
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,10 @@ def read
5959
@body.read
6060
end
6161

62+
def discard
63+
@body.discard
64+
end
65+
6266
def as_json(...)
6367
{
6468
class: self.class.name,

0 commit comments

Comments
 (0)