Skip to content

Commit

Permalink
update some comments
Browse files Browse the repository at this point in the history
  • Loading branch information
duwen committed Mar 7, 2019
1 parent d332663 commit e26784d
Show file tree
Hide file tree
Showing 15 changed files with 134 additions and 169 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ void getHttp() async {

- [Handling Errors](#handling-errors)

- [Using application/x-www-form-urlencoded format](#using-application/x-www-form-urlencoded-format)
- [Using application/x-www-form-urlencoded format](#using-applicationx-www-form-urlencoded-format)

- [Sending FormData](#sending-formdata)

Expand Down
1 change: 1 addition & 0 deletions example/adapter.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'dart:async';
import 'package:dio/dio.dart';

class MyAdapter extends HttpClientAdapter {
Expand Down
1 change: 1 addition & 0 deletions example/download.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'dart:async';
import 'dart:io';
import 'package:dio/dio.dart';

Expand Down
1 change: 1 addition & 0 deletions example/download_with_trunks.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'dart:async';
import 'dart:io';
import 'package:dio/dio.dart';

Expand Down
3 changes: 1 addition & 2 deletions example/flutter_example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ void main() {
// add interceptors
dio.interceptors..add(CookieManager(CookieJar()))..add(LogInterceptor());
(dio.transformer as DefaultTransformer).jsonDecodeCallback = parseJson;
dio.options.receiveTimeout = 1;
dio.post("http://www.dtworkroom.com/doris/1/2.0.0/test", data: {"a": 8}).then(print);
dio.options.receiveTimeout = 10000;
// (dio.httpClientAdapter as DefaultHttpClientAdapter).onHttpClientCreate =
// (client) {
// client.findProxy = (uri) {
Expand Down
1 change: 1 addition & 0 deletions example/post_stream_and_bytes.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'dart:async';
import 'dart:convert';
import 'dart:io';

Expand Down
5 changes: 1 addition & 4 deletions example/test.dart
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
import 'dart:convert';
import 'dart:io';

import 'package:dio/dio.dart';

main() async {
Dio dio = Dio();
dio.interceptors.add(LogInterceptor(requestBody: true));
dio.options.baseUrl = 'http://app.huka.com/';
dio.options.connectTimeout=5000;
dio.options.receiveTimeout=1;
dio.options.receiveTimeout=1000;
FormData formData = new FormData.from({
"phone": "13981983532",
"password": "xxxxx",
Expand Down
199 changes: 95 additions & 104 deletions package_src/lib/src/dio.dart
Original file line number Diff line number Diff line change
Expand Up @@ -325,70 +325,64 @@ class Dio {
});
}

/**
* Lock the current Dio instance.
*
* Dio will enqueue the incoming request tasks instead
* send them directly when [interceptor.request] is locked.
*
*/
/// Lock the current Dio instance.
///
/// Dio will enqueue the incoming request tasks instead
/// send them directly when [interceptor.request] is locked.
lock() {
interceptors.requestLock.lock();
}

/**
* Unlock the current Dio instance.
*
* Dio instance dequeue the request task。
*/
/// Unlock the current Dio instance.
///
/// Dio instance dequeue the request task。
unlock() {
interceptors.requestLock.unlock();
}

/**
* Clear the current Dio instance waiting queue.
*/
///Clear the current Dio instance waiting queue.
clear() {
interceptors.requestLock.clear();
}

/**
* Download the file and save it in local. The default http method is "GET",
* you can custom it by [Options.method].
*
* [urlPath]: The file url.
*
* [savePath]: The path to save the downloading file later. it can be a String or
* a callback:
* 1. A path with String type, eg "xs.jpg"
* 2. A callback `String Function(HttpHeaders responseHeaders)`; for example:
* ```dart
* await dio.download(url,(HttpHeaders responseHeaders){
* ...
* return "...";
* });
* ```
*
* [onReceiveProgress]: The callback to listen downloading progress.
* please refer to [ProgressCallback].
*
* [lengthHeader] : The real size of original file (not compressed).
* When file is compressed:
* 1. If this value is 'content-length', the `total` argument of `onProgress` will be -1
* 2. If this value is not 'content-length', maybe a custom header indicates the original
* file size , the `total` argument of `onProgress` will be this header value.
*
* you can also disable the compression by specifying the 'accept-encoding' header value as '*'
* to assure the value of `total` argument of `onProgress` is not -1. for example:
*
* await dio.download(url, "./example/flutter.svg",
* options: Options(headers: {HttpHeaders.acceptEncodingHeader: "*"}), // disable gzip
* onProgress: (received, total) {
* if (total != -1) {
* print((received / total * 100).toStringAsFixed(0) + "%");
* }
* });
*/
/// Download the file and save it in local. The default http method is "GET",
/// you can custom it by [Options.method].
///
/// [urlPath]: The file url.
///
/// [savePath]: The path to save the downloading file later. it can be a String or
/// a callback:
/// 1. A path with String type, eg "xs.jpg"
/// 2. A callback `String Function(HttpHeaders responseHeaders)`; for example:
/// ```dart
/// await dio.download(url,(HttpHeaders responseHeaders){
/// ...
/// return "...";
/// });
/// ```
///
/// [onReceiveProgress]: The callback to listen downloading progress.
/// please refer to [ProgressCallback].
///
/// [lengthHeader] : The real size of original file (not compressed).
/// When file is compressed:
/// 1. If this value is 'content-length', the `total` argument of `onProgress` will be -1
/// 2. If this value is not 'content-length', maybe a custom header indicates the original
/// file size , the `total` argument of `onProgress` will be this header value.
///
/// you can also disable the compression by specifying the 'accept-encoding' header value as '*'
/// to assure the value of `total` argument of `onProgress` is not -1. for example:
///
/// await dio.download(url, "./example/flutter.svg",
/// options: Options(headers: {HttpHeaders.acceptEncodingHeader: "*"}), // disable gzip
/// onProgress: (received, total) {
/// if (total != -1) {
/// print((received / total * 100).toStringAsFixed(0) + "%");
/// }
/// });
Future<Response> download(
String urlPath,
savePath, {
Expand Down Expand Up @@ -537,43 +531,41 @@ class Dio {
return await _listenCancelForAsyncTask(cancelToken, future);
}

/**
* Download the file and save it in local. The default http method is "GET",
* you can custom it by [Options.method].
*
* [uri]: The file uri.
*
* [savePath]: The path to save the downloading file later. it can be a String or
* a callback:
* 1. A path with String type, eg "xs.jpg"
* 2. A callback `String Function(HttpHeaders responseHeaders)`; for example:
* ```dart
* await dio.downloadUri(uri,(HttpHeaders responseHeaders){
* ...
* return "...";
* });
* ```
*
* [onReceiveProgress]: The callback to listen downloading progress.
* please refer to [ProgressCallback].
*
* [lengthHeader] : The real size of original file (not compressed).
* When file is compressed:
* 1. If this value is 'content-length', the `total` argument of `onProgress` will be -1
* 2. If this value is not 'content-length', maybe a custom header indicates the original
* file size , the `total` argument of `onProgress` will be this header value.
*
* you can also disable the compression by specifying the 'accept-encoding' header value as '*'
* to assure the value of `total` argument of `onProgress` is not -1. for example:
*
* await dio.download(url, "./example/flutter.svg",
* options: Options(headers: {HttpHeaders.acceptEncodingHeader: "*"}), // disable gzip
* onProgress: (received, total) {
* if (total != -1) {
* print((received / total * 100).toStringAsFixed(0) + "%");
* }
* });
*/
/// Download the file and save it in local. The default http method is "GET",
/// you can custom it by [Options.method].
///
/// [uri]: The file url.
///
/// [savePath]: The path to save the downloading file later. it can be a String or
/// a callback:
/// 1. A path with String type, eg "xs.jpg"
/// 2. A callback `String Function(HttpHeaders responseHeaders)`; for example:
/// ```dart
/// await dio.downloadUri(uri,(HttpHeaders responseHeaders){
/// ...
/// return "...";
/// });
/// ```
///
/// [onReceiveProgress]: The callback to listen downloading progress.
/// please refer to [ProgressCallback].
///
/// [lengthHeader] : The real size of original file (not compressed).
/// When file is compressed:
/// 1. If this value is 'content-length', the `total` argument of `onProgress` will be -1
/// 2. If this value is not 'content-length', maybe a custom header indicates the original
/// file size , the `total` argument of `onProgress` will be this header value.
///
/// you can also disable the compression by specifying the 'accept-encoding' header value as '*'
/// to assure the value of `total` argument of `onProgress` is not -1. for example:
///
/// await dio.downloadUri(uri, "./example/flutter.svg",
/// options: Options(headers: {HttpHeaders.acceptEncodingHeader: "*"}), // disable gzip
/// onProgress: (received, total) {
/// if (total != -1) {
/// print((received / total * 100).toStringAsFixed(0) + "%");
/// }
/// });
Future<Response> downloadUri(
Uri uri,
savePath, {
Expand All @@ -594,13 +586,12 @@ class Dio {
);
}

/**
* Make http request with options.
*
* [path] The url path.
* [data] The request data
* [options] The request options.
*/
/// Make http request with options.
///
/// [path] The url path.
/// [data] The request data
/// [options] The request options.
Future<Response<T>> request<T>(
String path, {
data,
Expand All @@ -621,13 +612,11 @@ class Dio {
);
}

/**
* Make http request with options.
*
* [uri] The uri.
* [data] The request data
* [options] The request options.
*/
/// Make http request with options.
///
/// [uri] The uri.
/// [data] The request data
/// [options] The request options.
Future<Response<T>> requestUri<T>(
Uri uri, {
data,
Expand Down Expand Up @@ -936,7 +925,9 @@ class Dio {
validateStatus: opt.validateStatus ??
options.validateStatus ??
(int status) => status >= 200 && status < 300 || status == 304,
receiveDataWhenStatusError: opt.receiveDataWhenStatusError??options.receiveDataWhenStatusError??true,
receiveDataWhenStatusError: opt.receiveDataWhenStatusError ??
options.receiveDataWhenStatusError ??
true,
followRedirects: opt.followRedirects ?? options.followRedirects ?? true,
maxRedirects: opt.maxRedirects ?? options.maxRedirects ?? 5,
queryParameters: query,
Expand Down
4 changes: 1 addition & 3 deletions package_src/lib/src/dio_error.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@ enum DioErrorType {
DEFAULT,
}

/**
* DioError describes the error info when request failed.
*/
/// DioError describes the error info when request failed.
class DioError extends Error {
DioError({
this.request,
Expand Down
12 changes: 4 additions & 8 deletions package_src/lib/src/form_data.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,8 @@ import 'dart:io';
import 'dart:math';
import 'upload_file_info.dart';

/**
* A class to create readable "multipart/form-data" streams.
* It can be used to submit forms and file uploads to http server.
*/
/// A class to create readable "multipart/form-data" streams.
/// It can be used to submit forms and file uploads to http server.
class FormData extends MapMixin<String, dynamic> {
var _map = new Map<String, dynamic>();
static const String _BOUNDARY_PRE_TAG = "----dio-boundary-";
Expand All @@ -22,9 +20,7 @@ class FormData extends MapMixin<String, dynamic> {
_init();
}

/**
* Create FormData instance with a Map.
*/
/// Create FormData instance with a Map.
FormData.from(Map<String, dynamic> other) {
_init();
addAll(other);
Expand Down Expand Up @@ -231,7 +227,7 @@ class FormData extends MapMixin<String, dynamic> {
if (value.bytes != null) {
for (var i = 0, p; i < value.bytes.length; i += 1024) {
p = i + 1024;
if(p > value.bytes.length) p = value.bytes.length;
if (p > value.bytes.length) p = value.bytes.length;
yield value.bytes.sublist(i, p);
}
} else {
Expand Down
Loading

0 comments on commit e26784d

Please sign in to comment.