Class: Protocol::HTTP1::Body::Chunked
- Inherits:
-
HTTP::Body::Readable
- Object
- HTTP::Body::Readable
- Protocol::HTTP1::Body::Chunked
- Defined in:
- lib/protocol/http1/body/chunked.rb
Instance Method Summary collapse
- #close(error = nil) ⇒ Object
- #empty? ⇒ Boolean
-
#initialize(stream) ⇒ Chunked
constructor
TODO maybe this should take a stream rather than a connection?.
- #inspect ⇒ Object
- #read ⇒ Object
Constructor Details
#initialize(stream) ⇒ Chunked
TODO maybe this should take a stream rather than a connection?
30 31 32 33 34 35 36 |
# File 'lib/protocol/http1/body/chunked.rb', line 30 def initialize(stream) @stream = stream @finished = false @length = 0 @count = 0 end |
Instance Method Details
#close(error = nil) ⇒ Object
42 43 44 45 46 47 48 49 50 |
# File 'lib/protocol/http1/body/chunked.rb', line 42 def close(error = nil) # We only close the connection if we haven't completed reading the entire body: unless @finished @stream.close @finished = true end super end |
#empty? ⇒ Boolean
38 39 40 |
# File 'lib/protocol/http1/body/chunked.rb', line 38 def empty? @finished end |
#inspect ⇒ Object
73 74 75 |
# File 'lib/protocol/http1/body/chunked.rb', line 73 def inspect "\#<#{self.class} #{@length} bytes read in #{@count} chunks>" end |
#read ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/protocol/http1/body/chunked.rb', line 52 def read return nil if @finished length = read_line.to_i(16) if length == 0 @finished = true read_line return nil end chunk = @stream.read(length) read_line # Consume the trailing CRLF @length += length @count += 1 return chunk end |