286: def read_chunked_encoding(resp, sock, parser)
287: out = StringIO.new
288: input = StringIO.new(resp.http_body)
289:
290:
291: status, result = read_chunks(input, out, parser)
292:
293: case status
294: when :incomplete_trailer
295: if result.nil?
296: sock.read(2)
297: else
298: sock.read((result.length - 2).abs)
299: end
300: when :incomplete_body
301: out.write(sock.read(result))
302: sock.read(2)
303: when :incomplete_header
304:
305: result.reverse!
306: result.each_byte {|b| sock.ungetc(b) }
307: when :finished
308:
309: out.rewind; return out.read
310: when :eof_error
311:
312: end
313:
314:
315: status, result = read_chunks(sock, out, parser)
316:
317:
318: out.rewind; return out.read
319: end