feat: Use IPNetwork.TryParse() for CIDR parsing#1122
Merged
Conversation
94f4535 to
0827cdd
Compare
Contributor
There was a problem hiding this comment.
Pull request overview
This PR simplifies trusted proxy CIDR parsing by replacing custom parsing logic with the framework-provided System.Net.IPNetwork.TryParse() API.
Changes:
- Removed manual CIDR string splitting, IP parsing, prefix validation, and network construction.
- Removed the now-unused
System.Net.Socketsimport.
Replace custom TryParseCidr implementation with the built-in System.Net.IPNetwork.TryParse() API. This eliminates manual parsing logic and leverages the framework's validated implementation. Changes: - Simplified TryParseCidr to one-liner using IPNetwork.TryParse - Removed manual split/validation of prefix length and address family - Removed unused AddressFamily import
0827cdd to
3731a30
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
The CIDR parsing logic was implemented with a custom helper that manually split strings, parsed integers, and validated prefix lengths. The .NET framework provides a built-in and thoroughly validated
IPNetwork.TryParse()API that handles all of this, eliminating the need for custom parsing code.Changes
TryParseCidr()wrapper method entirelyIPNetwork.TryParse()System.Net.SocketsimportThis eliminates unnecessary indirection while maintaining identical behavior and improving maintainability by relying on framework-tested APIs.