344: def read_response
345: resp = HttpResponse.new
346:
347: notify :read_header do
348: resp = read_parsed_header
349: end
350:
351: notify :read_body do
352: if resp.chunked_encoding?
353: read_chunked_body(resp)
354: elsif resp[CONTENT_LENGTH]
355: needs = resp[CONTENT_LENGTH].to_i - resp.http_body.length
356:
357:
358: resp.http_body += @sock.read(needs) if needs > 0 rescue HttpClientError
359: else
360: while true
361: begin
362: resp.http_body += @sock.read(CHUNK_SIZE, partial=true)
363: rescue HttpClientError
364: break
365: end
366: end
367: end
368: end
369:
370: store_cookies(resp)
371: return resp
372: end