Skip to content

Commit

Permalink
support maxRedirects config
Browse files Browse the repository at this point in the history
  • Loading branch information
duwen committed Mar 5, 2019
1 parent 8c667b3 commit 879a810
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
2 changes: 2 additions & 0 deletions package_src/lib/src/adapter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,9 @@ class DefaultHttpClientAdapter extends HttpClientAdapter {
type: DioErrorType.CONNECT_TIMEOUT,
);
}

request.followRedirects = options.followRedirects;
request.maxRedirects=options.maxRedirects;

if (options.method != "GET" && requestStream != null) {
// Transform the request data
Expand Down
1 change: 1 addition & 0 deletions package_src/lib/src/dio.dart
Original file line number Diff line number Diff line change
Expand Up @@ -937,6 +937,7 @@ class Dio {
options.validateStatus ??
(int status) => status >= 200 && status < 300 || status == 304,
followRedirects: opt.followRedirects ?? options.followRedirects ?? true,
maxRedirects: opt.maxRedirects ?? options.maxRedirects ?? 5,
queryParameters: query,
cookies: List.from(options.cookies ?? [])..addAll(opt.cookies ?? []),
);
Expand Down
20 changes: 20 additions & 0 deletions package_src/lib/src/options.dart
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ class BaseOptions extends _RequestConfig {
ValidateStatus validateStatus,
bool receiveDataWhenStatusError = true,
bool followRedirects = true,
int maxRedirects = 5,
}) : super(
method: method,
connectTimeout: connectTimeout,
Expand All @@ -50,6 +51,7 @@ class BaseOptions extends _RequestConfig {
receiveDataWhenStatusError: receiveDataWhenStatusError,
followRedirects: followRedirects,
cookies: cookies,
maxRedirects: maxRedirects,
);

/// Create a new Option from current instance with merging attributes.
Expand All @@ -67,6 +69,7 @@ class BaseOptions extends _RequestConfig {
ValidateStatus validateStatus,
bool receiveDataWhenStatusError,
bool followRedirects,
int maxRedirects,
}) {
return new BaseOptions(
method: method ?? this.method,
Expand All @@ -81,6 +84,7 @@ class BaseOptions extends _RequestConfig {
receiveDataWhenStatusError:
receiveDataWhenStatusError ?? this.receiveDataWhenStatusError,
followRedirects: followRedirects ?? this.followRedirects,
maxRedirects: maxRedirects ?? this.maxRedirects,
);
}

Expand All @@ -107,6 +111,7 @@ class Options extends _RequestConfig {
ValidateStatus validateStatus,
bool receiveDataWhenStatusError,
bool followRedirects,
int maxRedirects,
}) : super(
method: method,
connectTimeout: connectTimeout,
Expand All @@ -119,6 +124,7 @@ class Options extends _RequestConfig {
receiveDataWhenStatusError: receiveDataWhenStatusError,
followRedirects: followRedirects,
cookies: cookies,
maxRedirects: maxRedirects,
);

/// Create a new Option from current instance with merging attributes.
Expand All @@ -135,6 +141,7 @@ class Options extends _RequestConfig {
ValidateStatus validateStatus,
bool receiveDataWhenStatusError,
bool followRedirects,
int maxRedirects,
}) {
return new Options(
method: method ?? this.method,
Expand All @@ -149,6 +156,7 @@ class Options extends _RequestConfig {
receiveDataWhenStatusError:
receiveDataWhenStatusError ?? this.receiveDataWhenStatusError,
followRedirects: followRedirects ?? this.followRedirects,
maxRedirects: maxRedirects ?? this.maxRedirects,
);
}
}
Expand All @@ -172,6 +180,7 @@ class RequestOptions extends Options {
ValidateStatus validateStatus,
bool receiveDataWhenStatusError = true,
bool followRedirects = true,
int maxRedirects,
}) : super(
method: method,
connectTimeout: connectTimeout,
Expand All @@ -184,6 +193,7 @@ class RequestOptions extends Options {
validateStatus: validateStatus,
receiveDataWhenStatusError: receiveDataWhenStatusError,
followRedirects: followRedirects,
maxRedirects: maxRedirects,
);

/// generate uri
Expand Down Expand Up @@ -236,6 +246,7 @@ class _RequestConfig {
this.cookies,
this.receiveDataWhenStatusError = true,
this.followRedirects = true,
this.maxRedirects = 5,
}) : this.headers = headers ?? {},
this.extra = extra ?? {};

Expand Down Expand Up @@ -289,6 +300,15 @@ class _RequestConfig {
/// see [HttpClientRequest.followRedirects]
bool followRedirects;

/**
* Set this property to the maximum number of redirects to follow
* when [followRedirects] is `true`. If this number is exceeded
* an error event will be added with a [RedirectException].
*
* The default value is 5.
*/
int maxRedirects;

/// Custom Cookies for every request
List<Cookie> cookies;
}

0 comments on commit 879a810

Please sign in to comment.