Skip to content

Commit

Permalink
fix #474 #480
Browse files Browse the repository at this point in the history
  • Loading branch information
wendux committed Sep 26, 2019
1 parent 8bab3b1 commit dfd143e
Show file tree
Hide file tree
Showing 11 changed files with 36 additions and 30 deletions.
24 changes: 12 additions & 12 deletions README-ZH.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ void getHttp() async {

```dart
Response response;
Dio dio = new Dio();
Dio dio = Dio();
response = await dio.get("/test?id=12&name=wendu")
print(response.data.toString());
// 请求参数也可以通过对象传递,上面的代码等同于:
Expand Down Expand Up @@ -108,7 +108,7 @@ print(rs.data); //二进制数组
发送 FormData:

```dart
FormData formData = new FormData.from({
FormData formData = FormData.from({
"name": "wendux",
"age": 25,
});
Expand Down Expand Up @@ -173,20 +173,20 @@ await dio.post(
你可以使用默认配置或传递一个可选 `BaseOptions`参数来创建一个Dio实例 :

```dart
Dio dio = new Dio(); // 使用默认配置
Dio dio = Dio(); // 使用默认配置
// 配置dio实例
dio.options.baseUrl = "https://www.xx.com/api";
dio.options.connectTimeout = 5000; //5s
dio.options.receiveTimeout = 3000;
// 或者通过传递一个 `options`来创建dio实例
Options options = new BaseOptions(
Options options = BaseOptions(
baseUrl: "https://www.xx.com/api",
connectTimeout: 5000,
receiveTimeout: 3000,
);
Dio dio = new Dio(options);
Dio dio = Dio(options);
```


Expand Down Expand Up @@ -375,14 +375,14 @@ dio.interceptors.add(InterceptorsWrapper(
你可以通过调用拦截器的 `lock()`/`unlock` 方法来锁定/解锁拦截器。一旦请求/响应拦截器被锁定,接下来的请求/响应将会在进入请求/响应拦截器之前排队等待,直到解锁后,这些入队的请求才会继续执行(进入拦截器)。这在一些需要串行化请求/响应的场景中非常实用,后面我们将给出一个示例。

```dart
tokenDio = new Dio(); //Create a new instance to request the token.
tokenDio = Dio(); //Create a instance to request the token.
tokenDio.options = dio;
dio.interceptors.add(InterceptorsWrapper(
onRequest:(Options options) async {
// If no token, request token firstly and lock this interceptor
// to prevent other request enter this interceptor.
dio.interceptors.requestLock.lock();
// We use a new Dio(to avoid dead lock) instance to request token.
// We use a Dio(to avoid dead lock) instance to request token.
Response response = await tokenDio.get("/token");
//Set the token to headers
options.headers["token"] = response.data["data"]["token"];
Expand Down Expand Up @@ -651,8 +651,8 @@ import 'package:dio/adapter.dart';
//proxy all request to localhost:8888
return "PROXY localhost:8888";
};
// you can also create a new HttpClient to dio
// return new HttpClient();
// you can also create a HttpClient to dio
// return HttpClient();
};
```

Expand Down Expand Up @@ -680,10 +680,10 @@ String PEM="XXXXX"; // certificate content

```dart
(dio.httpClientAdapter as DefaultHttpClientAdapter).onHttpClientCreate = (client) {
SecurityContext sc = new SecurityContext();
SecurityContext sc = SecurityContext();
//file is the path of certificate
sc.setTrustedCertificates(file);
HttpClient httpClient = new HttpClient(context: sc);
HttpClient httpClient = HttpClient(context: sc);
return httpClient;
};
```
Expand All @@ -699,7 +699,7 @@ String PEM="XXXXX"; // certificate content
你可以通过 *cancel token* 来取消发起的请求:

```dart
CancelToken token = new CancelToken();
CancelToken token = CancelToken();
dio.get(url, cancelToken: token)
.catchError((DioError err){
if (CancelToken.isCancel(err)) {
Expand Down
6 changes: 2 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ A powerful Http client for Dart, which supports Interceptors, Global configurati

```yaml
dependencies:
dio: 3.x.x #latest version
dio: 3.x #latest version
```
> In order to support Flutter Web, v3.0.0 was heavily refactored, so it was not compatible with version 3.0.x. See [here](https://github.com/flutterchina/dio/blob/master/dio/CHANGELOG.md) for a detailed list of updates.
> In order to support Flutter Web, v3.x was heavily refactored, so it was not compatible with version 3.x See [here](https://github.com/flutterchina/dio/blob/master/dio/CHANGELOG.md) for a detailed list of updates.
### Super simple to use
Expand Down Expand Up @@ -559,8 +559,6 @@ FormData formData = FormData.from({
response = await dio.post("/info", data: formData);
```

> Note: Just the post method suppots FormData.
There is a complete example [here](https://github.com/flutterchina/dio/blob/master/example/formdata.dart).

### Multiple files upload
Expand Down
4 changes: 4 additions & 0 deletions dio/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@

# 3.0.2 2019.9.26

- fix #474 #480

# 3.0.2-dev.1 2019.9.20

- fix #470 #471
Expand Down
6 changes: 2 additions & 4 deletions dio/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ A powerful Http client for Dart, which supports Interceptors, Global configurati

```yaml
dependencies:
dio: 3.x.x #latest version
dio: 3.x #latest version
```
> In order to support Flutter Web, v3.0.0 was heavily refactored, so it was not compatible with version 3.0.x. See [here](https://github.com/flutterchina/dio/blob/master/dio/CHANGELOG.md) for a detailed list of updates.
> In order to support Flutter Web, v3.x was heavily refactored, so it was not compatible with version 3.x. See [here](https://github.com/flutterchina/dio/blob/master/dio/CHANGELOG.md) for a detailed list of updates.
### Super simple to use
Expand Down Expand Up @@ -559,8 +559,6 @@ FormData formData = FormData.from({
response = await dio.post("/info", data: formData);
```

> Note: Just the post method suppots FormData.
There is a complete example [here](https://github.com/flutterchina/dio/blob/master/example/formdata.dart).

### Multiple files upload
Expand Down
3 changes: 1 addition & 2 deletions dio/lib/src/dio.dart
Original file line number Diff line number Diff line change
Expand Up @@ -900,8 +900,7 @@ abstract class DioMixin implements Dio {
stream,
cancelToken?.whenCancel,
);
var headers =
Headers.fromMap(responseBody.headers ?? Map<String, String>());
var headers = Headers.fromMap(responseBody.headers ?? {});
Response ret = Response(
headers: headers,
request: options,
Expand Down
3 changes: 3 additions & 0 deletions dio/lib/src/multipart_file.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ import 'multipart_file_stub.dart'

/// A file to be uploaded as part of a [MultipartRequest]. This doesn't need to
/// correspond to a physical file.
///
/// MultipartFile is based on stream, and a stream can be read only once,
/// so the same MultipartFile can't be read multiple times.
class MultipartFile {
/// The size of the file in bytes. This must be known in advance, even if this
/// file is created from a [ByteStream].
Expand Down
5 changes: 3 additions & 2 deletions dio/lib/src/options.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ typedef ProgressCallback = void Function(int count, int total);
/// ResponseType indicates which transformation should
/// be automatically applied to the response data by Dio.
enum ResponseType {
/// Transform the response data to JSON object.
/// Transform the response data to JSON object only when the
/// content-type of response is "application/json" .
json,

/// Get the response stream without any transformation. The
Expand Down Expand Up @@ -189,7 +190,7 @@ class Options extends _RequestConfig {
extra: extra ?? Map.from(this.extra ?? {}),
headers: headers ?? Map.from(this.headers ?? {}),
responseType: responseType ?? this.responseType,
contentType: String ?? this.contentType,
contentType: contentType ?? this.contentType,
validateStatus: validateStatus ?? this.validateStatus,
receiveDataWhenStatusError:
receiveDataWhenStatusError ?? this.receiveDataWhenStatusError,
Expand Down
3 changes: 2 additions & 1 deletion dio/lib/src/transformer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,8 @@ class DefaultTransformer extends Transformer {
return responseBody;
}

_isJsonMime(String contentType) {
bool _isJsonMime(String contentType) {
if (contentType == null) return false;
return MediaType.parse(contentType).mimeType.toLowerCase() ==
Headers.jsonMimeType.mimeType;
}
Expand Down
2 changes: 1 addition & 1 deletion dio/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: dio
description: A powerful Http client for Dart, which supports Interceptors, FormData, Request Cancellation, File Downloading, Timeout etc.
version: 3.0.2-dev.1
version: 3.0.2
homepage: https://github.com/flutterchina/dio
author: wendux <[email protected]>

Expand Down
4 changes: 3 additions & 1 deletion example/test.dart
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import 'package:dio/dio.dart';

void getHttp() async {
var dio=Dio();
dio.interceptors.add(LogInterceptor());
try {
Response response = await Dio().get("http://www.google.com");
Response response = await dio.get("http://httpbin.org/");
print(response.data);
} catch (e) {
print(e);
Expand Down
6 changes: 3 additions & 3 deletions migration_to_3.0.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# 从2.1.x升级到 3.0.0
# 从2.1.x升级到 3.x

3.0.0为了同时支持Flutter、Flutter web,对项目进行了较大的重构,因此无法直接兼容2.1.x, 如果你是2.1.x用户,可以按照本文档指引升级到3.0.0.
3.x为了同时支持Flutter、Flutter web,对项目进行了较大的重构,因此无法直接兼容2.1.x, 如果你是2.1.x用户,可以按照本文档指引升级到3.x。

## 3.0.0 主要特性
## 3.x 主要特性

- 支持Flutter web
-[CookieManager](https://github.com/flutterchina/dio/tree/master/plugins/cookie_manager)抽离为单独的包
Expand Down

0 comments on commit dfd143e

Please sign in to comment.