-
Notifications
You must be signed in to change notification settings - Fork 31
fix: handle duplicate keys in logger state to prevent ArgumentException #961
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
Conversation
Replaces ToDictionary() with manual dictionary population to handle duplicate keys that can occur with HTTP headers (e.g., multiple Content-Type headers). The last value wins for duplicate keys, maintaining existing behavior. Performance improvements: - O(n) complexity instead of O(n log n) from GroupBy - Single pass enumeration - No LINQ overhead or intermediate collections Fixes issue where curl requests with duplicate headers caused: "An item with the same key has already been added. Key: Content-Type" Adds test case for duplicate key scenarios.
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## develop #961 +/- ##
===========================================
+ Coverage 77.39% 77.45% +0.06%
===========================================
Files 271 271
Lines 10874 10886 +12
Branches 1282 1284 +2
===========================================
+ Hits 8416 8432 +16
Misses 2041 2041
+ Partials 417 413 -4 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Do we need to consider this recursively for nested keys as well or will this not raise an
|
Good question, no it will not, for this case the key has to be unique, the value part is not considered in this code. If the value part is indeed a dictionary, the same rules apply (unique key) but they are not responsibility of this code and have to be fixed by the dictionary creator. |
Got it, makes sense. We are only dealing with appending the top level keys here and the values are handled by the user. Thanks! |
Issue number: #956
Summary
Changes
Fixes issue where requests with duplicate headers caused:
"An item with the same key has already been added. Key: Content-Type"
Replaces ToDictionary() with manual dictionary population to handle duplicate keys that can occur with HTTP headers (e.g., multiple Content-Type headers).
The last value wins for duplicate keys, maintaining existing behavior.
ToDictionary()
with manual dictionary population using indexer assignmentAdded test case
Log_WhenDuplicateKeysInState_LastValueWins()
that verifies:User experience
Checklist
Please leave checklist items unchecked if they do not apply to your change.
Is this a breaking change?
RFC issue number:
Checklist:
Acknowledgment
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.
Disclaimer: We value your time and bandwidth. As such, any pull requests created on non-triaged issues might not be successful.