Class: Protocol::HTTP1::Body::Remainder
- Inherits:
-
HTTP::Body::Readable
- Object
- HTTP::Body::Readable
- Protocol::HTTP1::Body::Remainder
- Defined in:
- lib/protocol/http1/body/remainder.rb
Constant Summary collapse
- BLOCK_SIZE =
1024 * 64
Instance Method Summary collapse
- #call(stream) ⇒ Object
- #close(error = nil) ⇒ Object
- #empty? ⇒ Boolean
-
#initialize(stream) ⇒ Remainder
constructor
block_size may be removed in the future.
- #inspect ⇒ Object
- #join ⇒ Object
-
#read ⇒ Object
TODO this is a bit less efficient in order to maintain compatibility with ‘IO`.
Constructor Details
#initialize(stream) ⇒ Remainder
block_size may be removed in the future. It is better managed by stream.
15 16 17 18 |
# File 'lib/protocol/http1/body/remainder.rb', line 15 def initialize(stream) @stream = stream @empty = false end |
Instance Method Details
#call(stream) ⇒ Object
42 43 44 45 46 47 48 |
# File 'lib/protocol/http1/body/remainder.rb', line 42 def call(stream) self.each do |chunk| stream.write(chunk) end stream.flush end |
#close(error = nil) ⇒ Object
24 25 26 27 28 29 30 |
# File 'lib/protocol/http1/body/remainder.rb', line 24 def close(error = nil) # We can't really do anything in this case except close the connection. @stream.close @empty = true super end |
#empty? ⇒ Boolean
20 21 22 |
# File 'lib/protocol/http1/body/remainder.rb', line 20 def empty? @empty or @stream.closed? end |
#inspect ⇒ Object
56 57 58 |
# File 'lib/protocol/http1/body/remainder.rb', line 56 def inspect "\#<#{self.class} #{@stream.closed? ? 'closed' : 'open'}>" end |
#join ⇒ Object
50 51 52 53 54 |
# File 'lib/protocol/http1/body/remainder.rb', line 50 def join @stream.read ensure @empty = true end |
#read ⇒ Object
TODO this is a bit less efficient in order to maintain compatibility with ‘IO`.
33 34 35 36 37 38 39 40 |
# File 'lib/protocol/http1/body/remainder.rb', line 33 def read @stream.readpartial(BLOCK_SIZE) rescue EOFError, IOError @empty = true # I noticed that in some cases you will get EOFError, and in other cases IOError!? return nil end |