forwardStream method
Forwards a request and returns a streaming response (e.g. for SSE).
Yields raw bytes as they arrive from the upstream server.
Implementation
Stream<List<int>> forwardStream(ProxyRequest request) async* {
var req = request;
if (_requestTransform != null) {
req = _requestTransform!(req);
}
final uri = _buildUri(req);
final httpReq = await _client!.openUrl(req.method, uri);
_applyHeaders(httpReq, req);
if (req.body != null) {
httpReq.write(req.body);
}
final httpResp = await httpReq.close();
_stats.requestCount++;
await for (final chunk in httpResp) {
_stats.bytesTransferred += chunk.length;
yield chunk;
}
}