Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master'
Browse files Browse the repository at this point in the history
# Conflicts:
#	package_src/lib/src/dio.dart
  • Loading branch information
wendux committed Aug 25, 2019
2 parents 596bf06 + 14e68c4 commit 6ea2c66
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 24 deletions.
4 changes: 4 additions & 0 deletions example/options.dart
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,8 @@ main() async {
contentType: ContentType.parse("application/x-www-form-urlencoded")),
);
print(response.data);

response = await dio.request("/get",
options: RequestOptions(baseUrl: "http://httpbin.org/"));
print(response.data);
}
51 changes: 27 additions & 24 deletions package_src/lib/src/dio.dart
Original file line number Diff line number Diff line change
Expand Up @@ -497,6 +497,7 @@ class Dio {
}).catchError((derr) async {
try {
await subscription.cancel();

} finally {
completer.completeError(_assureDioError(derr));
}
Expand Down Expand Up @@ -953,31 +954,33 @@ class Dio {
Options opt, String url, data, Map<String, dynamic> queryParameters) {
var query = (Map<String, dynamic>.from(options.queryParameters ?? {}))
..addAll(queryParameters ?? {});
final optBaseUrl = (opt is RequestOptions) ? opt.baseUrl: null;
return RequestOptions(
method: (opt.method ?? options.method)?.toUpperCase() ?? "GET",
headers: (Map.from(options.headers))..addAll(opt.headers),
baseUrl: options.baseUrl ?? "",
path: url,
data: data,
connectTimeout: opt.connectTimeout ?? options.connectTimeout ?? 0,
sendTimeout: opt.sendTimeout ?? options.sendTimeout ?? 0,
receiveTimeout: opt.receiveTimeout ?? options.receiveTimeout ?? 0,
responseType:
opt.responseType ?? options.responseType ?? ResponseType.json,
extra: (Map.from(options.extra))..addAll(opt.extra),
contentType: opt.contentType ?? options.contentType ?? ContentType.json,
validateStatus: opt.validateStatus ??
options.validateStatus ??
(int status) => status >= 200 && status < 300 || status == 304,
receiveDataWhenStatusError: opt.receiveDataWhenStatusError ??
options.receiveDataWhenStatusError ??
true,
followRedirects: opt.followRedirects ?? options.followRedirects ?? true,
maxRedirects: opt.maxRedirects ?? options.maxRedirects ?? 5,
queryParameters: query,
cookies: List.from(options.cookies ?? [])..addAll(opt.cookies ?? []),
requestEncoder: opt.requestEncoder ?? options.requestEncoder,
responseDecoder: opt.responseDecoder ?? options.responseDecoder);
method: (opt.method ?? options.method)?.toUpperCase() ?? "GET",
headers: (Map.from(options.headers))..addAll(opt.headers),
baseUrl: optBaseUrl ?? options.baseUrl ?? "",
path: url,
data: data,
connectTimeout: opt.connectTimeout ?? options.connectTimeout ?? 0,
sendTimeout: opt.sendTimeout ?? options.sendTimeout ?? 0,
receiveTimeout: opt.receiveTimeout ?? options.receiveTimeout ?? 0,
responseType:
opt.responseType ?? options.responseType ?? ResponseType.json,
extra: (Map.from(options.extra))..addAll(opt.extra),
contentType: opt.contentType ?? options.contentType ?? ContentType.json,
validateStatus: opt.validateStatus ??
options.validateStatus ??
(int status) => status >= 200 && status < 300 || status == 304,
receiveDataWhenStatusError: opt.receiveDataWhenStatusError ??
options.receiveDataWhenStatusError ??
true,
followRedirects: opt.followRedirects ?? options.followRedirects ?? true,
maxRedirects: opt.maxRedirects ?? options.maxRedirects ?? 5,
queryParameters: query,
cookies: List.from(options.cookies ?? [])..addAll(opt.cookies ?? []),
requestEncoder: opt.requestEncoder??options.requestEncoder,
responseDecoder: opt.responseDecoder??options.responseDecoder
);
}

Options _checkOptions(method, options) {
Expand Down
19 changes: 19 additions & 0 deletions package_src/test/dio_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -374,4 +374,23 @@ void main() {
]);
});
});

group("basic tests", () {
Dio dio;
setUp(() {
dio = Dio();
// dio.options.baseUrl = MockAdapter.mockBase;
dio.options.headers = {'User-Agent': 'dartisan', 'XX': '8'};
dio.httpClientAdapter = MockAdapter();
});
test("base url in request options", () async {
Response response;
response = await dio.get(
"/test",
queryParameters: {"id": '12', "name": "wendu"},
options: RequestOptions(baseUrl: MockAdapter.mockBase),
);
expect(response.data["errCode"], 0);
});
});
}

0 comments on commit 6ea2c66

Please sign in to comment.