mirror of
https://github.com/foss42/apidash.git
synced 2025-12-02 02:39:19 +08:00
better_networking: streaming implementation (streamHttpRequest)
This commit is contained in:
@@ -50,3 +50,20 @@ Future<http.Response> convertStreamedResponse(
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
Stream<String?> streamTextResponse(
|
||||
http.StreamedResponse streamedResponse,
|
||||
) async* {
|
||||
try {
|
||||
if (streamedResponse.statusCode != 200) {
|
||||
final errorText = await streamedResponse.stream.bytesToString();
|
||||
throw Exception('${streamedResponse.statusCode}\n$errorText');
|
||||
}
|
||||
final utf8Stream = streamedResponse.stream.transform(utf8.decoder);
|
||||
await for (final chunk in utf8Stream) {
|
||||
yield chunk;
|
||||
}
|
||||
} catch (e) {
|
||||
rethrow;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user