You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It seems like neither abort or cancel method are provided from http package, though there is abort in dart:io package for httpClientRequest.
Is it safe to call close on client for multipart request?
classMultipartRequestextends http.MultipartRequest {
/// Creates a new [MultipartRequest].var client = http.Client();
MultipartRequest(
String method,
Uri url, {
this.onProgress,
}) :super(method, url);
finalvoidFunction(int bytes, int totalBytes) onProgress;
voidcancel() => client.close();
@overrideFuture<http.StreamedResponse> send() async {
try {
var response =await client.send(this);
var stream =onDone(response.stream, client.close);
return http.StreamedResponse(
http.ByteStream(stream),
response.statusCode,
contentLength: response.contentLength,
request: response.request,
headers: response.headers,
isRedirect: response.isRedirect,
persistentConnection: response.persistentConnection,
reasonPhrase: response.reasonPhrase,
);
} catch (_) {
client.close();
rethrow;
}
}
Stream<T> onDone<T>(Stream<T> stream, voidFunction() onDone) =>
stream.transform(StreamTransformer.fromHandlers(handleDone: (sink) {
sink.close();
onDone();
}));
/// Freezes all mutable fields and returns a single-subscription [ByteStream] /// that will emit the request body.@override
http.ByteStreamfinalize() {
final byteStream =super.finalize();
if (onProgress ==null) return byteStream;
final total = contentLength;
var bytes =0;
final t =StreamTransformer.fromHandlers(
handleData: (List<int> data, EventSink<List<int>> sink) {
bytes += data.length;
if (onProgress !=null) onProgress(bytes, total);
sink.add(data);
},
);
final stream = byteStream.transform(t);
return http.ByteStream(stream);
}
}
I saw some error were thrown (can't reproduce again but it was complaining about the connection was closed, it had not been reached content length the request claimed to fulfill).
The text was updated successfully, but these errors were encountered:
Without additional information we're not able to resolve this issue. Feel free to add more info or respond to any questions above and we can reopen the case. Thanks for your contribution!
It seems like neither
abort
orcancel
method are provided from http package, though there isabort
in dart:io package for httpClientRequest.Is it safe to call
close
on client for multipart request?I saw some error were thrown (can't reproduce again but it was complaining about the connection was closed, it had not been reached content length the request claimed to fulfill).
The text was updated successfully, but these errors were encountered: