Class: Protocol::HTTP1::Body::Fixed
- Inherits:
-
HTTP::Body::Readable
- Object
- HTTP::Body::Readable
- Protocol::HTTP1::Body::Fixed
- Defined in:
- lib/protocol/http1/body/fixed.rb
Instance Attribute Summary collapse
-
#length ⇒ Object
readonly
Returns the value of attribute length.
-
#remaining ⇒ Object
readonly
Returns the value of attribute remaining.
Instance Method Summary collapse
- #close(error = nil) ⇒ Object
- #empty? ⇒ Boolean
-
#initialize(stream, length) ⇒ Fixed
constructor
A new instance of Fixed.
- #inspect ⇒ Object
- #join ⇒ Object
- #read ⇒ Object
Constructor Details
#initialize(stream, length) ⇒ Fixed
Returns a new instance of Fixed.
12 13 14 15 16 |
# File 'lib/protocol/http1/body/fixed.rb', line 12 def initialize(stream, length) @stream = stream @length = length @remaining = length end |
Instance Attribute Details
#length ⇒ Object (readonly)
Returns the value of attribute length.
18 19 20 |
# File 'lib/protocol/http1/body/fixed.rb', line 18 def length @length end |
#remaining ⇒ Object (readonly)
Returns the value of attribute remaining.
19 20 21 |
# File 'lib/protocol/http1/body/fixed.rb', line 19 def remaining @remaining end |
Instance Method Details
#close(error = nil) ⇒ Object
25 26 27 28 29 30 31 32 |
# File 'lib/protocol/http1/body/fixed.rb', line 25 def close(error = nil) # If we are closing the body without fully reading it, the underlying connection is now in an undefined state. if @remaining != 0 @stream.close end super end |
#empty? ⇒ Boolean
21 22 23 |
# File 'lib/protocol/http1/body/fixed.rb', line 21 def empty? @remaining == 0 end |
#inspect ⇒ Object
56 57 58 |
# File 'lib/protocol/http1/body/fixed.rb', line 56 def inspect "\#<#{self.class} length=#{@length} remaining=#{@remaining}>" end |
#join ⇒ Object
48 49 50 51 52 53 54 |
# File 'lib/protocol/http1/body/fixed.rb', line 48 def join buffer = @stream.read(@remaining) @remaining = 0 return buffer end |
#read ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/protocol/http1/body/fixed.rb', line 35 def read if @remaining > 0 # `readpartial` will raise `EOFError` if the stream is closed/finished: if chunk = @stream.readpartial(@remaining) @remaining -= chunk.bytesize return chunk # else # raise EOFError, "Stream closed with #{@remaining} bytes remaining!" end end end |