Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(dart): add Dio HttpClientAdapter to ClientOptions #3290

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,23 @@ final class ClientOptions {
/// Used only in case of using the default (dio) requester.
final Iterable<Interceptor>? interceptors;

/// Custom [HttpClientAdapter] used to send HTTP requests.
/// Used only in case of using the default (dio) requester.
final HttpClientAdapter? httpClientAdapter;

/// Constructs a [ClientOptions] instance with the provided parameters.
const ClientOptions(
{this.connectTimeout = const Duration(seconds: 2),
this.writeTimeout = const Duration(seconds: 30),
this.readTimeout = const Duration(seconds: 5),
this.hosts,
this.headers,
this.agentSegments,
this.requester,
this.logger,
this.interceptors});
const ClientOptions({
this.connectTimeout = const Duration(seconds: 2),
this.writeTimeout = const Duration(seconds: 30),
this.readTimeout = const Duration(seconds: 5),
this.hosts,
this.headers,
this.agentSegments,
this.requester,
this.logger,
this.interceptors,
this.httpClientAdapter,
});

@override
bool operator ==(Object other) =>
Expand All @@ -59,7 +65,8 @@ final class ClientOptions {
agentSegments == other.agentSegments &&
logger == other.logger &&
requester == other.requester &&
interceptors == other.interceptors;
interceptors == other.interceptors &&
httpClientAdapter == other.httpClientAdapter;

@override
int get hashCode =>
Expand All @@ -71,10 +78,11 @@ final class ClientOptions {
agentSegments.hashCode ^
logger.hashCode ^
requester.hashCode ^
interceptors.hashCode;
interceptors.hashCode ^
httpClientAdapter.hashCode;

@override
String toString() {
return 'ClientOptions{hosts: $hosts, connectTimeout: $connectTimeout, writeTimeout: $writeTimeout, readTimeout: $readTimeout, headers: $headers, agentSegments: $agentSegments, logger: $logger, requester: $requester, interceptors: $interceptors}';
return 'ClientOptions{hosts: $hosts, connectTimeout: $connectTimeout, writeTimeout: $writeTimeout, readTimeout: $readTimeout, headers: $headers, agentSegments: $agentSegments, logger: $logger, requester: $requester, interceptors: $interceptors, httpClientAdapter: $httpClientAdapter}';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class DioRequester implements Requester {
Iterable<AgentSegment>? clientSegments,
Function(Object?)? logger,
Iterable<Interceptor>? interceptors,
HttpClientAdapter? httpClientAdapter,
}) : _client = Dio(
BaseOptions(
headers: headers,
Expand All @@ -49,7 +50,11 @@ class DioRequester implements Requester {
logPrint: logger,
),
if (interceptors != null) ...interceptors,
]);
]) {
if (httpClientAdapter != null) {
_client.httpClientAdapter = httpClientAdapter;
}
}

@override
Future<HttpResponse> perform(HttpRequest request) async {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ final class RetryStrategy {
clientSegments: [segment, ...?options.agentSegments],
logger: options.logger,
interceptors: options.interceptors,
httpClientAdapter: options.httpClientAdapter,
),
);

Expand Down
Loading