Use standard Clojure map for cookies #621
Merged
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.
Clojure
sorted-mapandsorted-setare useful in some scenarios but can present problems in others:apply-on-form-params,test-encode-cookies, andtest-wrap-cookiesget,contains?,find,dissoc,select-keys, etc throw ClassCastException when given incompatible keys https://clojure.atlassian.net/browse/CLJ-2693=andclojure.data/diffcan yield exceptions https://clojure.atlassian.net/browse/CLJ-2325 https://clojure.atlassian.net/browse/CLJ-1983prandprintgenerate strings indistinguishable from unsorted map/setprint-dupgenerates unreadable strings https://clojure.atlassian.net/browse/CLJ-1733I propose to avoid
sorted-mapfor values in the clj-http:cookiesmap. Looking at the commit history, I'm unable to determine why a sorted-map was used initially. The change away from sorted-map doesn't break any tests and doesn't appear to have any substantive effect on clj-http behavior, but perhaps there are some use cases I'm not familiar with.Of course, I probably should provide a justification or example of obvious downside to this use of sorted-map 😉 so I'll attempt to explain:
We expect
getorfindto returnnilwhen a key isn't present in a map, and that's what we observe when serializing the response map from service1 to EDN and reading this EDN in service2. We were surprised when the same code threw ClassCastException when executed within service1.While I wouldn't expect another clj-http user to run into exactly this set of circumstances, the potential for inconsistent behavior, this inconvenient behavior of sorted-map, the lack of obvious upside to using sorted-map for cookie values, and the minimal clj-http code change lead me to believe this is a worthwhile change.
In the meantime, we've adjusted our code to coerce these sorted-maps to standard Clojure maps, so I won't claim that we're blocked on this clj-http change. My goal here is to document the concern and attempt to make a case for this change, but remain open-minded about the approach and probably learn something in the process 😄
Happy to discuss alternatives, concerns, etc.
Thanks your ongoing maintenance and stewardship of clj-http @dakrone 😃