lib/protocol/http/body/readable.rb in protocol-http-0.35.0 vs lib/protocol/http/body/readable.rb in protocol-http-0.36.0
- old
+ new
@@ -131,9 +131,19 @@
def finish
# Internally, this invokes `self.each` which then invokes `self.close`.
Buffered.read(self)
end
+ # Discard the body as efficiently as possible.
+ #
+ # The default implementation simply reads all chunks until the body is empty.
+ #
+ # Useful for discarding the body when it is not needed, but preserving the underlying connection.
+ def discard
+ while chunk = self.read
+ end
+ end
+
def as_json(...)
{
class: self.class.name,
length: self.length,
stream: self.stream?,