Rename to contentTimeout
diff --git a/lib/src/base_client.dart b/lib/src/base_client.dart
index fb5bd91..8e1445a 100644
--- a/lib/src/base_client.dart
+++ b/lib/src/base_client.dart
@@ -84,7 +84,8 @@
/// later point, or it could already be closed when it's returned. Any
/// internal HTTP errors should be wrapped as [ClientException]s.
@override
- Future<StreamedResponse> send(BaseRequest request, {Duration? timeout});
+ Future<StreamedResponse> send(BaseRequest request,
+ {Duration? contentTimeout});
/// Sends a non-streaming [Request] and returns a non-streaming [Response].
Future<Response> _sendUnstreamed(
@@ -110,7 +111,7 @@
}
}
- return Response.fromStream(await send(request, timeout: timeout));
+ return Response.fromStream(await send(request, contentTimeout: timeout));
}
/// Throws an error if [response] is not successful.
diff --git a/lib/src/base_request.dart b/lib/src/base_request.dart
index f4ddac6..156e20d 100644
--- a/lib/src/base_request.dart
+++ b/lib/src/base_request.dart
@@ -2,6 +2,7 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
+import 'dart:async';
import 'dart:collection';
import 'package:meta/meta.dart';
@@ -117,11 +118,18 @@
/// the request is complete. If you're planning on making multiple requests to
/// the same server, you should use a single [Client] for all of those
/// requests.
- Future<StreamedResponse> send({Duration? timeout}) async {
+ ///
+ /// If [contentTimeout] is not null the request will be aborted if it takes
+ /// longer than the given duration to receive the entire response. If the
+ /// timeout occurs before any reply is received from the server the returned
+ /// future will as an error with a [TimeoutException]. If the timout occurs
+ /// after the reply has been started but before the entire body has been read
+ /// the response stream will emit a [TimeoutException] and close.
+ Future<StreamedResponse> send({Duration? contentTimeout}) async {
var client = Client();
try {
- var response = await client.send(this, timeout: timeout);
+ var response = await client.send(this, contentTimeout: contentTimeout);
var stream = onDone(response.stream, client.close);
return StreamedResponse(ByteStream(stream), response.statusCode,
contentLength: response.contentLength,
diff --git a/lib/src/browser_client.dart b/lib/src/browser_client.dart
index b77da8d..46ad363 100644
--- a/lib/src/browser_client.dart
+++ b/lib/src/browser_client.dart
@@ -41,9 +41,10 @@
/// Sends an HTTP request and asynchronously returns the response.
@override
- Future<StreamedResponse> send(BaseRequest request, {Duration? timeout}) {
+ Future<StreamedResponse> send(BaseRequest request,
+ {Duration? contentTimeout}) {
final completer = Completer<StreamedResponse>();
- _send(request, timeout, completer);
+ _send(request, contentTimeout, completer);
return completer.future;
}
diff --git a/lib/src/client.dart b/lib/src/client.dart
index 291e39b..ba162db 100644
--- a/lib/src/client.dart
+++ b/lib/src/client.dart
@@ -182,13 +182,14 @@
/// Sends an HTTP request and asynchronously returns the response.
///
- /// If [timeout] is not null the request will be aborted if it takes longer
- /// than the given duration to complete. If the timeout occurs before any
- /// reply is received from the server the returned future will as an error
- /// with a [TimeoutException]. If the timout occurs after the reply has been
- /// started but before the entire body has been read the response stream will
- /// emit a [TimeoutException] and close.
- Future<StreamedResponse> send(BaseRequest request, {Duration? timeout});
+ /// If [contentTimeout] is not null the request will be aborted if it takes
+ /// longer than the given duration to receive the entire response. If the
+ /// timeout occurs before any reply is received from the server the returned
+ /// future will as an error with a [TimeoutException]. If the timout occurs
+ /// after the reply has been started but before the entire body has been read
+ /// the response stream will emit a [TimeoutException] and close.
+ Future<StreamedResponse> send(BaseRequest request, {Duration?
+ contentTimeout});
/// Closes the client and cleans up any resources associated with it.
///
diff --git a/lib/src/io_client.dart b/lib/src/io_client.dart
index fe2f849..90809fe 100644
--- a/lib/src/io_client.dart
+++ b/lib/src/io_client.dart
@@ -24,23 +24,25 @@
/// Sends an HTTP request and asynchronously returns the response.
@override
- Future<IOStreamedResponse> send(BaseRequest request, {Duration? timeout}) {
+ Future<IOStreamedResponse> send(BaseRequest request,
+ {Duration? contentTimeout}) {
final completer = Completer<IOStreamedResponse>();
- _send(request, timeout, completer);
+ _send(request, contentTimeout, completer);
return completer.future;
}
- Future<void> _send(BaseRequest request, Duration? timeout,
+ Future<void> _send(BaseRequest request, Duration? contentTimeout,
Completer<IOStreamedResponse> completer) async {
var stream = request.finalize();
Timer? timer;
void Function() onTimeout;
- if (timeout != null) {
+ if (contentTimeout != null) {
onTimeout = () {
- completer.completeError(TimeoutException('Request aborted', timeout));
+ completer
+ .completeError(TimeoutException('Request aborted', contentTimeout));
};
- timer = Timer(timeout, () {
+ timer = Timer(contentTimeout, () {
onTimeout();
});
}
@@ -55,10 +57,11 @@
ioRequest.headers.set(name, value);
});
- if (timeout != null) {
+ if (contentTimeout != null) {
onTimeout = () {
ioRequest.abort();
- completer.completeError(TimeoutException('Request aborted', timeout));
+ completer.completeError(
+ TimeoutException('Request aborted', contentTimeout));
};
}
@@ -70,7 +73,7 @@
headers[key] = values.join(',');
});
var wasTimedOut = false;
- if (timeout != null) {
+ if (contentTimeout != null) {
onTimeout = () {
wasTimedOut = true;
response.detachSocket().then((socket) => socket.destroy());
@@ -83,7 +86,7 @@
StreamTransformer.fromHandlers(handleDone: (sink) {
timer?.cancel();
if (wasTimedOut) {
- sink.addError(TimeoutException('Request aborted', timeout));
+ sink.addError(TimeoutException('Request aborted', contentTimeout));
}
sink.close();
}));
diff --git a/lib/src/mock_client.dart b/lib/src/mock_client.dart
index 731f0b1..0931206 100644
--- a/lib/src/mock_client.dart
+++ b/lib/src/mock_client.dart
@@ -66,7 +66,7 @@
@override
Future<StreamedResponse> send(BaseRequest request,
- {Duration? timeout}) async {
+ {Duration? contentTimeout}) async {
var bodyStream = request.finalize();
return await _handler(request, bodyStream);
}