ResponseCollector¶
Accumulates streaming response callbacks into a buffered HTTPResponse.
Create a fresh ResponseCollector for each request/response cycle. On
keep-alive connections where multiple requests are sent sequentially, use a
new collector per request rather than reusing one.
Typical usage in HTTPClientLifecycleEventReceiver callbacks:
var _collector: ResponseCollector = ResponseCollector
fun ref on_response(response: Response val) =>
_collector = ResponseCollector
_collector.set_response(response)
fun ref on_body_chunk(data: Array[U8] val) =>
_collector.add_chunk(data)
fun ref on_response_complete() =>
try
let response = _collector.build()?
// use response.status, response.body, etc.
end
The collector concatenates all chunks into a single contiguous Array[U8]
val. For large responses, this means the full body is held in memory. Users
who need streaming for large downloads should use the raw on_body_chunk()
callbacks directly.
Constructors¶
create¶
Create an empty response collector.
Returns¶
- ResponseCollector ref^
Public Functions¶
set_response¶
Store the response metadata (version, status, reason, headers).
Must be called before build(). Typically called from on_response().
Parameters¶
- response: Response val
Returns¶
- None val
add_chunk¶
Append a body chunk. Typically called from on_body_chunk().
Chunks are concatenated in order when build() is called.
Parameters¶
Returns¶
- None val
build¶
Build the final HTTPResponse from the stored response and chunks.
Returns the buffered response with all chunks concatenated into a single
Array[U8] val.
Partial: errors if set_response() was never called, since the collector
would have no status, version, or headers to populate.
Returns¶
- HTTPResponse val ?