Skip to content
Permalink
Browse files

update to 2.0.3 preRelease

  • Loading branch information...
duwen
duwen committed Feb 14, 2019
1 parent a10ffbf commit 2842ce2e36ccd0d692b7ba42ec03016132e322e5
@@ -1,15 +1 @@
analyzer:
strong-mode: true
# exclude:
# - path/to/excluded/files/**

# Lint rules and documentation, see http://dart-lang.github.io/linter/lints
linter:
rules:
- cancel_subscriptions
- hash_and_equals
- iterable_contains_unrelated_type
- list_remove_unrelated_type
- test_types_in_equals
- unrelated_type_equality_checks
- valid_regexps
include: package:pedantic/analysis_options.yaml
@@ -12,8 +12,8 @@ main() async {

// The follow three requests with the same token.
var url1 = "https://accounts.google.com";
var url2 = "https://www.facebook.com";
var url3 = "https://www.baidu.com";
// var url2 = "https://www.facebook.com";
// var url3 = "https://www.baidu.com";
Response response;
try {
response = await dio.get(url1, cancelToken: token);
@@ -1,4 +1,3 @@
import 'dart:io';
import 'package:cookie_jar/cookie_jar.dart';
import 'package:dio/dio.dart';

@@ -1,4 +1,3 @@
import 'dart:io';
import 'package:dio/dio.dart';

class CacheInterceptor extends Interceptor {
@@ -42,7 +42,7 @@ Future download2(Dio dio, String url, String savePath) async {
var raf = file.openSync(mode: FileMode.write);
// response.data is List<int> type
raf.writeFromSync(response.data);
raf.close();
await raf.close();
} catch (e) {
print(e);
}
@@ -29,9 +29,9 @@ main() async {
"file": UploadFileInfo(File("./example/upload.txt"), "upload.txt"),
"file2": UploadFileInfo.fromBytes(utf8.encode("hello world"), "word.txt"),
});

//Response response = await dio.post("/token", data: formData);
Response response = await dio.post("http://localhost:3000/upload",
Response response;
response = await dio.post("/token", data: formData);
response = await dio.post("http://localhost:3000/upload",
data: formData2, cancelToken: CancelToken());
print(response.statusCode);
//Response response = await dio.post("http://localhost/ds/test", data: formData);
@@ -3,15 +3,16 @@ import 'package:dio/dio.dart';

main() async {
var dio = new Dio(new BaseOptions(
baseUrl: "http://www.dtworkroom.com/doris/1/2.0.0/",
connectTimeout: 5000,
receiveTimeout: 100000,
// 5s
headers: {"user-agent": "dio", "api": "1.0.0"},
contentType: ContentType.JSON,
// Transform the response data to a String encoded with UTF8.
// The default value is [ResponseType.JSON].
responseType: ResponseType.plain));
baseUrl: "http://www.dtworkroom.com/doris/1/2.0.0/",
connectTimeout: 5000,
receiveTimeout: 100000,
// 5s
headers: {"user-agent": "dio", "api": "1.0.0"},
contentType: ContentType.json,
// Transform the response data to a String encoded with UTF8.
// The default value is [ResponseType.JSON].
responseType: ResponseType.plain,
));

Response<String> response;

@@ -21,7 +21,7 @@ main() async {
Response<String> response;
//response= await dio.get("https://github.com/wendux/fly");
response = await dio.get("https://www.baidu.com");
//print(response.data);
print(response.statusCode);
response = await dio.get("https://www.baidu.com");
//print(response.data);
print(response.statusCode);
}
@@ -1,12 +1,11 @@
import 'dart:async';
import 'dart:io';

import 'package:dio/dio.dart';

main() async {
var dio = new Dio();
dio.interceptors.add(LogInterceptor(responseBody: true));
dio.get(
await dio.get(
"http://www.dtworkroom.com/doris/1/2.0.0/test",
queryParameters: {"kk": "tt"},
options: Options(
@@ -1,5 +1,4 @@
import 'dart:async';
import 'dart:io';
import 'package:dio/dio.dart';

/// If the request data is a `List` type, the [DefaultTransformer] will send data
@@ -29,7 +29,7 @@ class CancelToken {
/// Cancel the request
void cancel([String msg]) {
_cancelError = new DioError(message: msg, type: DioErrorType.CANCEL);
if (!completers.isEmpty) {
if (completers.isNotEmpty) {
completers.forEach((e) => e.completeError(cancelError));

/// Don't remove [completers] here, [Dio] will remove the completer automatically.
@@ -494,8 +494,9 @@ class Dio {
},
cancelOnError: true,
);
// ignore: unawaited_futures
cancelToken?.whenCancel?.then((_) async {
subscription.cancel();
await subscription.cancel();
await _closeAndDelete();
});
return await _listenCancelForAsyncTask(cancelToken, future);
@@ -681,7 +682,7 @@ class Dio {
ret.data = await _listenCancelForAsyncTask(
cancelToken, transformer.transformResponse(options, responseBody));
} else {
responseBody.stream.listen(null).cancel();
await responseBody.stream.listen(null).cancel();
}
_checkCancelled(cancelToken);
if (statusOk) {
@@ -94,7 +94,7 @@ class FormData extends MapMixin<String, dynamic> {
}
});

if (_map.length > 0 || fileMap.length > 0) {
if (_map.isNotEmpty || fileMap.isNotEmpty) {
data.clear();
data.write(boundary + "--");
_writeln(data);
@@ -172,8 +172,8 @@ class RequestOptions extends Options {
ResponseType responseType,
ContentType contentType,
ValidateStatus validateStatus,
bool receiveDataWhenStatusError: true,
bool followRedirects: true,
bool receiveDataWhenStatusError = true,
bool followRedirects = true,
}) : super(
method: method,
baseUrl: baseUrl,
@@ -238,8 +238,8 @@ class _RequestConfig {
this.contentType,
this.validateStatus,
this.cookies,
this.receiveDataWhenStatusError: true,
this.followRedirects: true,
this.receiveDataWhenStatusError = true,
this.followRedirects = true,
}) {
// set the default user-agent with Dio version
this.headers = headers ?? {};
@@ -122,8 +122,9 @@ class DefaultTransformer extends Transformer {
onDone: () => completer.complete(),
cancelOnError: true,
);
// ignore: unawaited_futures
options.cancelToken?.whenCancel?.then((_) {
subscription.cancel();
return subscription.cancel();
});
await completer.future;
if (options.responseType == ResponseType.bytes) return buffer;
@@ -15,4 +15,5 @@ dependencies:
dev_dependencies:
test: ^1.5.1
test_coverage: ^0.2.0
pedantic: '1.1.0'

@@ -83,7 +83,7 @@ void main() {
});
var f = new File("./example/flutter.svg");
var t = await f.open();
t.close();
await t.close();
});
});

@@ -161,7 +161,7 @@ void main() {
} catch (e) {
expect(e.message, "Can't send List to sever directly");
}
dio.get("/test").then((r) {
await dio.get("/test").then((r) {
expect(r.request.extra["xx"], "extra");
});
var data = {

0 comments on commit 2842ce2

Please sign in to comment.
You can’t perform that action at this time.