Class: Async::HTTP::Protocol::HTTP11::ChunkedBody
- Inherits:
-
Object
- Object
- Async::HTTP::Protocol::HTTP11::ChunkedBody
- Defined in:
- lib/async/http/protocol/http11.rb
Instance Method Summary collapse
- #close ⇒ Object
- #closed? ⇒ Boolean
- #each ⇒ Object
-
#initialize(protocol) ⇒ ChunkedBody
constructor
A new instance of ChunkedBody.
- #read ⇒ Object
Constructor Details
#initialize(protocol) ⇒ ChunkedBody
Returns a new instance of ChunkedBody.
184 185 186 187 |
# File 'lib/async/http/protocol/http11.rb', line 184 def initialize(protocol) @protocol = protocol @closed = false end |
Instance Method Details
#close ⇒ Object
224 225 226 |
# File 'lib/async/http/protocol/http11.rb', line 224 def close self.each {} end |
#closed? ⇒ Boolean
189 190 191 |
# File 'lib/async/http/protocol/http11.rb', line 189 def closed? @closed end |
#each ⇒ Object
193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 |
# File 'lib/async/http/protocol/http11.rb', line 193 def each return if @closed while true size = @protocol.read_line.to_i(16) if size == 0 @protocol.read_line @closed = true return end chunk = @protocol.stream.read(size) @protocol.read_line # Consume the trailing CRLF yield chunk end end |
#read ⇒ Object
214 215 216 217 218 219 220 221 222 |
# File 'lib/async/http/protocol/http11.rb', line 214 def read buffer = Async::IO::BinaryString.new self.each do |chunk| buffer << chunk end return buffer end |