Class: PatientHttp::ResponseReader
- Inherits:
-
Object
- Object
- PatientHttp::ResponseReader
- Defined in:
- lib/patient_http/response_reader.rb
Overview
Reads and validates HTTP response bodies.
Encapsulates the logic for reading async HTTP responses with size validation and building Response objects from the raw response data.
Instance Method Summary collapse
-
#initialize(processor) ⇒ ResponseReader
constructor
Initialize the reader.
-
#read_body(async_response, headers_hash) ⇒ String?
Read the response body with size validation.
Constructor Details
#initialize(processor) ⇒ ResponseReader
Initialize the reader.
12 13 14 |
# File 'lib/patient_http/response_reader.rb', line 12 def initialize(processor) @processor = processor end |
Instance Method Details
#read_body(async_response, headers_hash) ⇒ String?
Read the response body with size validation.
Reads the async HTTP response body asynchronously to completion, which allows the connection to be reused. The async-http client handles connection pooling and keep-alive internally. Using iteration instead of read() ensures non-blocking I/O that yields to the reactor.
27 28 29 30 31 32 33 |
# File 'lib/patient_http/response_reader.rb', line 27 def read_body(async_response, headers_hash) return nil unless async_response.body validate_content_length(headers_hash) body = read_body_chunks(async_response) apply_charset_encoding(body, headers_hash) end |