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
A powerful Http client for Dart, which supports Interceptors, Global configuration, FormData, Request Cancellation, File downloading, Timeout etc.
10
10
11
11
### Add dependency
12
12
13
13
```yaml
14
14
dependencies:
15
-
dio: 2.1.x #latest version
15
+
dio: 2.2.x #latest version
16
16
```
17
-
If you are using 1.x , this doc can help you upgrade to 2.x. [Change log](https://github.com/flutterchina/dio/blob/master/CHANGELOG.md)
17
+
> In order to support Flutter Web, v2.2.0 was heavily refactored, so it was not compatible with version 2.1.x. See [here](https://github.com/flutterchina/dio/blob/master/dio/CHANGELOG.md) for a detailed list of updates.
You can lock/unlock the interceptors by calling their `lock()`/`unlock` method. Once the request/response interceptor is locked, the incoming request/response will be added to a queue before they enter the interceptor, they will not be continued until the interceptor is unlocked.
@@ -421,7 +408,7 @@ Because of security reasons, we need all the requests to set up a csrfToken in t
CookieManager Interceptor can help us manage the request/response cookies automaticly. CookieManager depends on `cookieJar` package :
458
-
459
-
> The dio cookie manage API is based on the withdrawn [cookie_jar](https://github.com/flutterchina/cookie_jar).
460
-
461
-
You can create a `CookieJar` or `PersistCookieJar` to manage cookies automatically, and dio use the `CookieJar` by default, which saves the cookies **in RAM**. If you want to persists cookies, you can use the `PersistCookieJar` class, the example codes as follows:
462
-
463
-
```dart
464
-
var dio = new Dio();
465
-
dio.interceptors.add(CookieManager(CookieJar()))
466
-
```
467
-
468
-
`PersistCookieJar` is a cookie manager which implements the standard cookie policy declared in RFC. `PersistCookieJar` persists the cookies in files, so if the application exit, the cookies always exist unless call `delete` explicitly.
469
-
470
-
> Note: In flutter, the path passed to `PersistCookieJar` must be valid(exists in phones and with write access). you can use [path_provider](https://pub.dartlang.org/packages/path_provider) package to get right path
442
+
### Custom Interceptor
471
443
472
-
More details about [cookie_jar](https://github.com/flutterchina/cookie_jar) see : https://github.com/flutterchina/cookie_jar.
444
+
You can custom interceptor by extending the `Interceptor` class. There is an example that implementing a simple cache policy: [custom cache interceptor](https://github.com/flutterchina/dio/blob/master/example/custom_cache_interceptor.dart).
473
445
474
-
### Custom Interceptor
446
+
##Cookie Manager
475
447
476
-
You can custom interceptor by extending the `Interceptor` class. There is an example that implementing a simple cache policy: custom cache interceptor.
448
+
[dio_cookie_manager](https://github.com/flutterchina/dio/tree/master/plugins/cookie_manager) package is a cookie manager for Dio.
477
449
478
450
## Handling Errors
479
451
@@ -514,9 +486,6 @@ try {
514
486
/// The original error/exception object; It's usually not null when `type`
515
487
/// is DioErrorType.DEFAULT
516
488
dynamic error;
517
-
518
-
/// Error stacktrace info
519
-
StackTrace stackTrace;
520
489
}
521
490
```
522
491
@@ -550,22 +519,21 @@ By default, Dio serializes request data(except String type) to `JSON`. To send d
@@ -583,6 +551,7 @@ There is a complete example [here](https://github.com/flutterchina/dio/blob/mast
583
551
If you use dio in flutter development, you'd better to decode json in background with [compute] function.
584
552
585
553
```dart
554
+
586
555
// Must be top-level function
587
556
_parseAndDecode(String response) {
588
557
return jsonDecode(response);
@@ -625,6 +594,9 @@ dio.httpClientAdapter = new DefaultHttpClientAdapter();
625
594
`DefaultHttpClientAdapter` provide a callback to set proxy to `dart:io:HttpClient`, for example:
626
595
627
596
```dart
597
+
import 'package:dio/dio.dart';
598
+
import 'package:dio/adapter.dart';
599
+
...
628
600
(dio.httpClientAdapter as DefaultHttpClientAdapter).onHttpClientCreate = (client) {
629
601
// config the http client
630
602
client.findProxy = (uri) {
@@ -668,12 +640,16 @@ Another way is creating a `SecurityContext` when create the `HttpClient`:
668
640
669
641
In this way, the format of certificate must be PEM or PKCS12.
670
642
643
+
## Http2 support
644
+
645
+
[dio_http2_adapter](https://github.com/flutterchina/dio/tree/master/plugins/http2_adapter) package is a Dio HttpClientAdapter which support Http/2.0 .
646
+
671
647
## Cancellation
672
648
673
649
You can cancel a request using a *cancel token*. One token can be shared with multiple requests. When a token's `cancel` method invoked, all requests with this token will be cancelled.
Copy file name to clipboardexpand all lines: dio/CHANGELOG.md
+30
Original file line number
Diff line number
Diff line change
@@ -1,3 +1,33 @@
1
+
# 2.2.0
2
+
3
+
### New features
4
+
5
+
- Support Flutter Web.
6
+
- Extract [CookieManager](https://github.com/flutterchina/dio/tree/master/plugins/cookie_manager) into a separate package(No need for Flutter Web).
7
+
- Provides a [HTTP/2.0 HttpClientAdapter](https://github.com/flutterchina/dio/tree/master/plugins/http2_adapter).
8
+
9
+
### Change List
10
+
11
+
-~~Options.cookies~~
12
+
13
+
-~~Options.connectionTimeout~~ ;We should config connection timed out in `BaseOptions`. For keep-alive reasons, not every request requires a separate connection。
14
+
15
+
-`Options.followRedirects`、`Options.maxRedirects`、`Response.redirects` don't make sense in Flutter Web,because redirection can be automatically handled by browsers.
- The return type of Interceptor's callback changes from `FutureOr<dynamic>` to `Future`. The reason is [here](https://dart.dev/guides/language/effective-dart/design#avoid-using-futureort-as-a-return-type) .
24
+
25
+
- The type of `Response.headers` changes from `HttpHeaders` to `Headers`, because `HttpHeaders` is in "dart:io" library which is not supported in Flutter Web.
0 commit comments