Class: HTTTee::Server::Dechunker::ChunkedBody
- Inherits:
-
Object
- Object
- HTTTee::Server::Dechunker::ChunkedBody
- Extended by:
- Forwardable
- Defined in:
- lib/htttee/server/middleware/dechunker.rb
Constant Summary collapse
- CRLF =
"\r\n"
Instance Attribute Summary collapse
-
#input ⇒ Object
readonly
Returns the value of attribute input.
Instance Method Summary collapse
- #dechunk(chunk, &blk) ⇒ Object
- #each(&blk) ⇒ Object
-
#initialize(input) ⇒ ChunkedBody
constructor
A new instance of ChunkedBody.
Constructor Details
#initialize(input) ⇒ ChunkedBody
Returns a new instance of ChunkedBody.
27 28 29 |
# File 'lib/htttee/server/middleware/dechunker.rb', line 27 def initialize(input) @input, @buffer = input, '' end |
Instance Attribute Details
#input ⇒ Object (readonly)
Returns the value of attribute input.
23 24 25 |
# File 'lib/htttee/server/middleware/dechunker.rb', line 23 def input @input end |
Instance Method Details
#dechunk(chunk, &blk) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/htttee/server/middleware/dechunker.rb', line 37 def dechunk(chunk, &blk) @buffer << chunk loop do return unless @buffer[CRLF] string_length, remainder = @buffer.split(CRLF, 2) length = string_length.to_i(16) if length == 0 @buffer = '' @input.succeed return elsif remainder.size >= length + 2 # length + CRLF data, @buffer = remainder[0...length], remainder[(length+2)..-1] blk.call(data) else return end end end |
#each(&blk) ⇒ Object
31 32 33 34 35 |
# File 'lib/htttee/server/middleware/dechunker.rb', line 31 def each(&blk) @input.each do |chunk| dechunk(chunk, &blk) end end |