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