Skip to content

Cache Basic auth header on Realm#2267

Open
pavel-ptashyts wants to merge 2 commits into
AsyncHttpClient:mainfrom
maygemdev:perf/basic-auth-header-cache
Open

Cache Basic auth header on Realm#2267
pavel-ptashyts wants to merge 2 commits into
AsyncHttpClient:mainfrom
maygemdev:perf/basic-auth-header-cache

Conversation

@pavel-ptashyts

@pavel-ptashyts pavel-ptashyts commented Jul 19, 2026

Copy link
Copy Markdown
Contributor

Summary

  • memoize the generated HTTP Basic authorization header on immutable Realm instances
  • reuse one cached header for both request and proxy Basic authentication
  • document Realm.getBasicAuthHeader() as an intentional public API introduced in 3.0.12
  • document that concurrent first access may perform benign duplicate computation
  • verify request and proxy paths return the same cached String instance

API note

The accessor is public because Realm and the Netty authentication utilities are in different packages. It exposes only the immutable derived header value and avoids adding mutable cache management to the public surface.

Validation

  • ./mvnw -pl client -Dtest='org.asynchttpclient.util.AuthenticatorUtilsTest,org.asynchttpclient.RealmTest' test (44 tests)
  • existing focused authentication, compile, and package checks from the initial change

Attribution

Codex on behalf of Pavel Ptashyts

@pavel-ptashyts
pavel-ptashyts force-pushed the perf/basic-auth-header-cache branch from 9466f51 to b071fff Compare July 20, 2026 08:50
Cache the generated HTTP Basic authorization header on immutable
Realm instances so repeated preemptive and proxy Basic auth requests
can reuse the same header string. This avoids rebuilding credentials
and Base64 output on every dispatch.

Add a regression test that verifies repeated per-request Basic auth
header generation returns the cached value.

Codex on behalf of Pavel Ptashyts

Co-Authored-By: Codex <codex@openai.com>
@pavel-ptashyts
pavel-ptashyts force-pushed the perf/basic-auth-header-cache branch from 9ea7c4f to 06d225a Compare July 20, 2026 15:08
Document the lazy cache semantics of Realm.getBasicAuthHeader(),
including its intentional public API status and benign duplicate
computation during concurrent first access.

Extend the regression test to verify that request and proxy
authentication reuse the same cached header instance.

Codex on behalf of Pavel Ptashyts

Co-Authored-By: Codex <codex@openai.com>
@pavel-ptashyts
pavel-ptashyts force-pushed the perf/basic-auth-header-cache branch from 06d225a to f167215 Compare July 20, 2026 15:23
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.

1 participant