Module: Async::HTTP::Body::Reader
Overview
General operations for interacting with a request or response body.
Instance Method Summary collapse
-
#body? ⇒ Boolean
Whether there is a body?.
-
#close(error = nil) ⇒ Object
Close the connection as quickly as possible.
-
#each {|String| ... } ⇒ Object
Read chunks from the body.
-
#finish ⇒ Buffered
Gracefully finish reading the body.
-
#read ⇒ String
Reads the entire request/response body.
Instance Method Details
#body? ⇒ Boolean
Whether there is a body?
66 67 68 |
# File 'lib/async/http/body/reader.rb', line 66 def body? @body and !@body.empty? end |
#close(error = nil) ⇒ Object
Close the connection as quickly as possible. Discards body. May close the underlying connection if necessary to terminate the stream.
58 59 60 61 62 63 |
# File 'lib/async/http/body/reader.rb', line 58 def close(error = nil) if @body @body.close(error) @body = nil end end |
#each {|String| ... } ⇒ Object
Read chunks from the body.
28 29 30 31 32 33 |
# File 'lib/async/http/body/reader.rb', line 28 def each(&block) if @body @body.each(&block) @body = nil end end |
#finish ⇒ Buffered
Gracefully finish reading the body. This will buffer the remainder of the body.
48 49 50 51 52 53 54 55 |
# File 'lib/async/http/body/reader.rb', line 48 def finish if @body body = @body.finish @body = nil return body end end |
#read ⇒ String
Reads the entire request/response body.
37 38 39 40 41 42 43 44 |
# File 'lib/async/http/body/reader.rb', line 37 def read if @body buffer = @body.join @body = nil return buffer end end |