chore: simplify auth challenge parser and Digest qop helper#195
Merged
Conversation
Behavior-preserving cleanups in the http/auth package, all confined to
private members (no public-API change):
- recoverToNextChallenge now reuses readQuotedString() instead of
carrying a second, near-identical quoted-string skip that had to stay
byte-for-byte in step with it. On an unterminated string the reader
consumes through to EOF, exactly where recovery wants to land.
- parseAuthParamOrToken68 hoists the repeated "rewind to saved, read a
token68, yield token68" sequence into one local function, so the three
disambiguation branches read as the decision they make.
- Back the token / token68 character sets with String constants rather
than Set<Char>. The `c in ...` membership test resolves to
CharSequence.contains, dropping per-character boxing, the HashSet
lookup on the hot parse path, and the one-time set allocation.
- Collapse qopSupportsAuth's accumulate-and-return loop to a single
short-circuiting any { } expression, keeping the legacy null guard.
The existing AuthChallengeParserTest / DigestChallengeHandlerTest suites
cover these paths.
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
Behavior-preserving simplifications in
sdk-core'shttp/authpackage, confined to two files and entirely toprivatemembers — no public-API movement, soapiCheckis unaffected. The existingAuthChallengeParserTest/DigestChallengeHandlerTestsuites exercise these paths.Changes
AuthChallengeParser.ktrecoverToNextChallengereusesreadQuotedString(). The recovery loop carried a second, near-identical quoted-string skip that had to stay byte-for-byte in step withreadQuotedString()— same opening-quote skip, same\-escape handling, same run-to-EOF on an unterminated string, same landing one past the closing quote. Calling the existing reader (and discarding the result) keeps that logic in one place. This is the error-recovery (cold) path, so the reader's discardedStringBuilderis a non-issue.token68, yield\"token68\" to …" sequence was repeated across all three disambiguation branches. A local function closing oversaved/cursorstates it once.Stringconstants instead ofSet<Char>.isTokenChar/isToken68Charrun once per input character; against aStringthe samec in …test compiles toCharSequence.contains— a direct scan of a ≤14-char literal — removing the per-characterCharboxing andHashSetlookup on the hot parse path, plus the one-time set allocation.DigestChallengeHandler.ktqopSupportsAuthto a single expression. The accumulate-and-return loop is exactlyany { … }with the same short-circuiting; the legacynull(qop-absent) guard is kept.Verification
I traced the recovery-loop edge cases (normal string, escaped inner quote, unterminated string, dangling trailing backslash) to confirm
readQuotedString()lands the cursor at the identical position the old hand-rolled skip did. Locally::sdk-core:test(auth suites),compileKotlin(withallWarningsAsErrors),ktlint,detekt, andapiCheckall pass.Closes #170