Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
πŸ› Address PR #2512 review: keep min SDK at 2.18, drop fromSocket
Per @AlexV525:

1. Revert dio/pubspec.yaml + dio_test/pubspec.yaml min SDK back to
   `>=2.18.0 <4.0.0` (the bump to 3.5.0 is no longer needed).
2. Revert dio/lib/src/dio_mixin.dart to `abstract class DioMixin` with
   the original TODO comment.
3. Replace the Dart-3.5+ `ConnectionTask.fromSocket(...)` call in
   `_pinnedConnectionFactory` with `SecureSocket.startConnect(...)` and
   return the stock SDK [ConnectionTask] it produces. We await
   `task.socket` once to do the leaf-cert validation; HttpClient
   re-awaits the same `Future<SecureSocket>` and gets the resolved
   value immediately (Future await is idempotent).

   This works on every Dart >=2.18.0 because `SecureSocket.startConnect`
   has been in `dart:io` well before the minimum SDK, and the
   `ConnectionTask` generic is covariant in its type parameter so
   `ConnectionTask<SecureSocket>` is implicitly assignable to
   `ConnectionTask<Socket>` at the factory's return position. No
   vendoring or `implements ConnectionTask` is required β€” and
   `ConnectionTask` being `final class` from Dart 3.0 onward is no
   longer a problem since we never inherit from it.

   The maintainer's suggestion to literally "copy ConnectionTask into
   the code base" cannot be done across the Dart 3.0–3.4 window (final
   class blocks implements; fromSocket didn't exist yet), but
   `SecureSocket.startConnect` achieves the same end with zero new
   types and zero SDK floor change.

4. Drop the two CHANGELOG bullets that referenced the SDK bump and
   the mixin migration. The rest of the entry (the actual #2418 fix)
   stays.

No test changes β€” the factory's observable behavior is unchanged
(approval yields a validated SecureSocket; rejection still throws
`_BadCertificateException` from the same point in `_fetch`'s try
block). All 222 tests pass; `dart analyze lib/` is clean.
  • Loading branch information
realmeylisdev committed May 11, 2026
commit 8a66e1ebd3b907cd9569a396e4d9efaa5ef8c8db
4 changes: 0 additions & 4 deletions dio/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,6 @@ See the [Migration Guide][] for the complete breaking changes list.**
users already configure via `badCertificateCallback: (_, _, _) => true`
in the existing pinning example), so self-signed and pinned-CA setups
work without supplying `createHttpClient`.
- Raise the minimum Dart SDK to 3.5.0 (Flutter 3.24+). Required for the
`ConnectionTask.fromSocket` API used by the pre-emission path.
- Migrate `DioMixin` to `mixin class` syntax now that the SDK floor is
Dart 3.

## 5.9.2

Expand Down
49 changes: 29 additions & 20 deletions dio/lib/src/adapters/io_adapter.dart

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about other adapters?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The fix is intentionally scoped to IOHttpClientAdapter since that's the adapter with the bug. Quick rundown of the others:

  • plugins/http2_adapter β€” already does pre-emission validation correctly at connection_manager_imp.dart:133-150. This PR brings IOHttpClientAdapter to parity.
  • plugins/web_adapter β€” no validateCertificate field exists on the web adapter; TLS is browser-controlled and not introspectable from Dart. Not applicable.
  • plugins/native_dio_adapter β€” delegates to cronet_http / cupertino_http; TLS pinning is platform-native (Android NSC, iOS ATS/TrustKit), not a dio-level callback. Not applicable.

Happy to add this as a one-line cross-reference comment in io_adapter.dart if you'd like that captured in source.

Original file line number Diff line number Diff line change
Expand Up @@ -361,26 +361,35 @@ class IOHttpClientAdapter implements HttpClientAdapter {
// is honored on every new connection.
final validator = validateCertificate;

final socketFuture = () async {
final ss = await SecureSocket.connect(
url.host,
url.port,
supportedProtocols: const ['http/1.1'],
// When [validateCertificate] is set, defer all certificate
// validation to the user's callback. This makes self-signed and
// pinned-CA setups work without forcing the user to also supply
// [createHttpClient].
onBadCertificate: validator == null ? null : (_) => true,
);
if (validator != null) {
final cert = ss.peerCertificate;
if (!validator(cert, url.host, url.port)) {
ss.destroy();
throw _BadCertificateException(url.host, url.port, cert);
}
// [SecureSocket.startConnect] returns a stock SDK [ConnectionTask] β€”
// available since well before dio's min SDK of 2.18 β€” so we don't
// need [ConnectionTask.fromSocket] (Dart 3.5+) and don't need to
// subclass/vendor [ConnectionTask] (which is `final class` from Dart
// 3.0). We await `task.socket` once here to do the leaf-cert check,
// then return the same task; [HttpClient] re-awaits `task.socket`
// and gets the already-resolved [SecureSocket] immediately.
//
// Covariance: [ConnectionTask] has no bound on its type parameter,
// so [ConnectionTask<SecureSocket>] is implicitly assignable to
// [ConnectionTask<Socket>] at the return position.
final task = await SecureSocket.startConnect(
url.host,
url.port,
supportedProtocols: const ['http/1.1'],
// When [validateCertificate] is set, defer all certificate
// validation to the user's callback. This makes self-signed and
// pinned-CA setups work without forcing the user to also supply
// [createHttpClient].
onBadCertificate: validator == null ? null : (_) => true,
);
if (validator != null) {
final ss = await task.socket;
final cert = ss.peerCertificate;
if (!validator(cert, url.host, url.port)) {
ss.destroy();
throw _BadCertificateException(url.host, url.port, cert);
}
return ss;
}();
return ConnectionTask.fromSocket(socketFuture, () {});
}
return task;
}
}
3 changes: 2 additions & 1 deletion dio/lib/src/dio_mixin.dart

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please revert since we don't match the requirement here.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reverted in 8a66e1e β€” back to abstract class DioMixin implements Dio with the original TODO(EVERYONE): Use \mixin class` when the lower bound of SDK is raised to 3.0.0.` comment.

Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ import 'transformer.dart';

part 'interceptor.dart';

abstract mixin class DioMixin implements Dio {
// TODO(EVERYONE): Use `mixin class` when the lower bound of SDK is raised to 3.0.0.
abstract class DioMixin implements Dio {
/// The base request config for the instance.
@override
late BaseOptions options;
Expand Down
2 changes: 1 addition & 1 deletion dio/pubspec.yaml

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please revert.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reverted in 8a66e1e β€” back to sdk: '>=2.18.0 <4.0.0'. Same for dio_test/pubspec.yaml. The pre-emission factory no longer needs Dart 3.5+.

Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ repository: https://github.com/cfug/dio/blob/main/dio
issue_tracker: https://github.com/cfug/dio/issues

environment:
sdk: '>=3.5.0 <4.0.0'
sdk: '>=2.18.0 <4.0.0'

dependencies:
async: ^2.8.2
Expand Down
2 changes: 1 addition & 1 deletion dio_test/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ repository: https://github.com/cfug/dio/blob/main/dio_test
issue_tracker: https://github.com/cfug/dio/issues

environment:
sdk: '>=3.5.0 <4.0.0'
sdk: '>=2.18.0 <4.0.0'

dependencies:
dio: any
Expand Down
Loading