Skip to content

Commit cdfa361

Browse files
authored
Merge branch 'master' into master
2 parents 057d4ef + 778174b commit cdfa361

11 files changed

+29
-22
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
## 0.13.4-dev
22

33
* Add `onSendProgress` callback
4+
* Throw a more useful error when a client is used after it has been closed.
45

56
## 0.13.3
67

README.md

+5-2
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,12 @@ If you do this, make sure to close the client when you're done:
3030
```dart
3131
var client = http.Client();
3232
try {
33-
var uriResponse = await client.post(Uri.parse('https://example.com/whatsit/create'),
33+
var response = await client.post(
34+
Uri.https('example.com', 'whatsit/create'),
3435
body: {'name': 'doodle', 'color': 'blue'});
35-
print(await client.get(uriResponse.bodyFields['uri']));
36+
var decodedResponse = jsonDecode(utf8.decode(response.bodyBytes)) as Map;
37+
var uri = Uri.parse(decodedResponse['uri'] as String);
38+
print(await client.get(uri));
3639
} finally {
3740
client.close();
3841
}

analysis_options.yaml

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
1-
include: package:pedantic/analysis_options.yaml
1+
include: package:lints/recommended.yaml
22

33
analyzer:
44
strong-mode:
55
implicit-casts: false
6-
enable-experiment:
7-
- non-nullable
86

97
linter:
108
rules:

lib/src/browser_client.dart

+1-2
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,13 @@ import 'dart:async';
66
import 'dart:html';
77
import 'dart:typed_data';
88

9-
import 'package:pedantic/pedantic.dart' show unawaited;
10-
119
import 'base_client.dart';
1210
import 'base_request.dart';
1311
import 'byte_stream.dart';
1412
import 'exception.dart';
1513
import 'progress.dart';
1614
import 'streamed_response.dart';
15+
import 'utils.dart' show unawaited;
1716

1817
/// Create a [BrowserClient].
1918
///

lib/src/byte_stream.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class ByteStream extends StreamView<List<int>> {
1313
/// Returns a single-subscription byte stream that will emit the given bytes
1414
/// in a single chunk.
1515
factory ByteStream.fromBytes(List<int> bytes) =>
16-
ByteStream(Stream.fromIterable([bytes]));
16+
ByteStream(Stream.value(bytes));
1717

1818
/// Collects the data of this stream in a [Uint8List].
1919
Future<Uint8List> toBytes() {

lib/src/io_client.dart

+5
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@ class IOClient extends BaseClient {
2828
BaseRequest request, {
2929
Progress? onSendProgress,
3030
}) async {
31+
if (_inner == null) {
32+
throw ClientException(
33+
'HTTP request failed. Client is already closed.', request.url);
34+
}
35+
3136
var stream = request.finalize();
3237

3338
try {

lib/src/utils.dart

+3
Original file line numberDiff line numberDiff line change
@@ -74,3 +74,6 @@ Stream<T> onDone<T>(Stream<T> stream, void Function() onDone) =>
7474
sink.close();
7575
onDone();
7676
}));
77+
78+
// TODO: Remove after Dart 2.14 is stable
79+
void unawaited<T>(Future<T> future) {}

pubspec.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ dependencies:
1111
http_parser: ^4.0.0
1212
meta: ^1.3.0
1313
path: ^1.8.0
14-
pedantic: ^1.10.0
1514

1615
dev_dependencies:
1716
fake_async: ^1.2.0
17+
lints: ^1.0.0
1818
shelf: ^1.1.0
1919
test: ^1.16.0

test/io/http_test.dart

+10-11
Original file line numberDiff line numberDiff line change
@@ -375,17 +375,16 @@ void main() {
375375
expect(response.statusCode, equals(200));
376376
expect(
377377
response.body,
378-
parse(equals({
379-
'method': 'DELETE',
380-
'path': '/',
381-
'headers': {
382-
'content-length': ['0'],
383-
'accept-encoding': ['gzip'],
384-
'user-agent': ['Dart'],
385-
'x-random-header': ['Value'],
386-
'x-other-header': ['Other Value']
387-
}
388-
})));
378+
parse(allOf(
379+
containsPair('method', 'DELETE'),
380+
containsPair('path', '/'),
381+
containsPair(
382+
'headers',
383+
allOf(
384+
containsPair('accept-encoding', ['gzip']),
385+
containsPair('user-agent', ['Dart']),
386+
containsPair('x-random-header', ['Value']),
387+
containsPair('x-other-header', ['Other Value']))))));
389388
});
390389

391390
test('read', () async {

test/io/utils.dart

-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import 'dart:io';
77

88
import 'package:http/http.dart';
99
import 'package:http/src/utils.dart';
10-
import 'package:pedantic/pedantic.dart';
1110
import 'package:test/test.dart';
1211

1312
export '../utils.dart';

test/response_test.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import 'dart:async';
66

77
import 'package:http/http.dart' as http;
8-
import 'package:pedantic/pedantic.dart';
8+
import 'package:http/src/utils.dart' show unawaited;
99
import 'package:test/test.dart';
1010

1111
void main() {

0 commit comments

Comments
 (0)