chore: streamline http/common header merge, media-type guards, and ETag predicate#191
Merged
Merged
Conversation
…ag predicate
Behavior-preserving cleanups in the http.common package:
- Headers.addAll now iterates the source's backing map directly instead of
building a fully defensive entries() snapshot that is discarded after one pass.
- MediaType.toString reuses the fullType getter rather than rebuilding
"type/subtype" inline twice.
- The wildcard-type guard in MediaType.of/parse is rewritten without the double
negative, reading directly as the documented invariant.
- The quoted-value unescape loop in MediaType.parse is lifted into a named
unescapeQuotedValue helper, the inverse of formatParameterValue.
- ETag.parse drops the redundant !startsWith("W/") term, which is always true
once the strong-form test already requires a leading quote.
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.
Summary
Five small, behavior-preserving simplifications in the
http.commonpackage. None change observable behavior or the public API surface (apiCheckis unaffected); they remove a throwaway allocation, collapse duplicated string builds, untangle a double-negative guard, name an anonymous block, and drop an always-true term from a predicate.Changes
Headers.addAlliterates the source's backingheadersMapdirectly (as the copy constructor already does) instead of going throughentries(), which allocates aLinkedHashMapplus per-list and whole-map unmodifiable wrappers only to discard them after a single iteration. Keys are already canonical, so the merge result is identical.MediaType.toStringreuses the existingfullTypegetter rather than rebuilding"type/subtype"inline, keeping the bare wire form defined in one place.MediaType.of/MediaType.parsewildcard guard rewritten from!(type == "*" && subtype != "*")totype != "*" || subtype == "*"(De Morgan). Same truth table and error messages, but it now reads directly as the documented invariant: a wildcard type is only allowed when the subtype is also a wildcard.MediaType.parsequoted-value unescape loop extracted into a namedprivate fun unescapeQuotedValue, the inverse offormatParameterValue, flattening the parameter-parsing loop.ETag.parsedrops the redundant!startsWith("W/")term from the strong-form test:startsWith("\"")already forces a leading quote, which aW/-prefixed weak form can never have, so the term was always true once reached.Testing
./gradlew :sdk-core:test(MediaType/Headers/ETag suites),ktlintCheck,detekt, andapiCheckall pass.Closes #173