Skip to content

Consolidate loopback host checking in devtools_shared - #10112

Open
johnpryan wants to merge 1 commit into
flutter:masterfrom
johnpryan:consolidate-loopback-host-check
Open

johnpryan wants to merge 1 commit into
flutter:masterfrom
johnpryan:consolidate-loopback-host-check

Conversation

@johnpryan

Copy link
Copy Markdown
Contributor
  • Update isLoopbackHost to use web-safe Uri.parseIPv4Address and Uri.parseIPv6Address (supporting localhost, 127.0.0.0/8, and canonical/expanded IPv6 ::1).
  • Remove the duplicate _isLoopbackHost helper in ServerApi and delegate to isLoopbackHost.
  • Add unit tests for isLoopbackHost in service_utils_test.dart.

- Update isLoopbackHost to use web-safe Uri.parseIPv4Address and Uri.parseIPv6Address (supporting localhost, 127.0.0.0/8, and canonical/expanded IPv6 ::1).
- Remove the duplicate _isLoopbackHost helper in ServerApi and delegate to isLoopbackHost.
- Add unit tests for isLoopbackHost in service_utils_test.dart.
@johnpryan
johnpryan marked this pull request as ready for review December 2, 2026 21:08

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request refactors the isLoopbackHost utility in packages/devtools_shared to be web-safe by removing dart:io dependencies and utilizing Uri.parseIPv4Address and Uri.parseIPv6Address. The ServerApi class has been updated to use this refactored utility, and comprehensive unit tests have been added to verify the loopback host logic. A review comment suggests using ListEquality for IPv6 byte comparison to improve code readability and maintain consistency with existing patterns.

Comment on lines +51 to +54
for (var i = 0; i < 15; i++) {
if (bytes[i] != 0) return false;
}
return bytes[15] == 1;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

[CONCERN] To improve readability, avoid magic numbers, and maintain consistency with how IP address bytes are compared elsewhere in the codebase (e.g., ServerApi._hostsMatch using ListEquality), we can compare the parsed IPv6 bytes directly to the expected loopback byte array using ListEquality from package:collection.

      const ipv6LoopbackBytes = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1];
      return const ListEquality<int>().equals(bytes, ipv6LoopbackBytes);
References
  1. Adhering to consistent style across all DevTools packages improves collaboration and reduces errors. Avoid using raw/magic strings or numbers. Extract them into descriptive named constants so the intent and meaning of the values are clear. (link)

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant