Skip to content

chore: streamline http/common header merge, media-type guards, and ETag predicate#191

Merged
OmarAlJarrah merged 1 commit into
mainfrom
chore/http-common-simplifications
Jun 28, 2026
Merged

chore: streamline http/common header merge, media-type guards, and ETag predicate#191
OmarAlJarrah merged 1 commit into
mainfrom
chore/http-common-simplifications

Conversation

@OmarAlJarrah

Copy link
Copy Markdown
Member

Summary

Five small, behavior-preserving simplifications in the http.common package. None change observable behavior or the public API surface (apiCheck is 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.addAll iterates the source's backing headersMap directly (as the copy constructor already does) instead of going through entries(), which allocates a LinkedHashMap plus 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.toString reuses the existing fullType getter rather than rebuilding "type/subtype" inline, keeping the bare wire form defined in one place.
  • MediaType.of / MediaType.parse wildcard guard rewritten from !(type == "*" && subtype != "*") to type != "*" || 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.parse quoted-value unescape loop extracted into a named private fun unescapeQuotedValue, the inverse of formatParameterValue, flattening the parameter-parsing loop.
  • ETag.parse drops the redundant !startsWith("W/") term from the strong-form test: startsWith("\"") already forces a leading quote, which a W/-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, and apiCheck all pass.

Closes #173

…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.
@OmarAlJarrah OmarAlJarrah merged commit 5acd605 into main Jun 28, 2026
1 check passed
@OmarAlJarrah OmarAlJarrah deleted the chore/http-common-simplifications branch June 28, 2026 01:16
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.

http/common: streamline Headers.addAll, MediaType guards/toString/unescape, and ETag predicate

1 participant