Skip to content

Fix #254 — User-Agent header missing in Release builds#277

Closed
RicardoKoch wants to merge 1 commit into
okta:masterfrom
RicardoKoch:fix/254-user-agent-release-builds
Closed

Fix #254 — User-Agent header missing in Release builds#277
RicardoKoch wants to merge 1 commit into
okta:masterfrom
RicardoKoch:fix/254-user-agent-release-builds

Conversation

@RicardoKoch

Copy link
Copy Markdown
Contributor

SDKVersion.userAgent is populated as a side effect of evaluating the lazy 'static let' registration in each Version+*.swift. Every dereference site is currently spelled 'assert(SDKVersion.X != nil)' — but Swift's assert(_:) takes its condition as @autoclosure, which the optimizer strips in -O builds. In Release builds the lazies never fire, SDKVersion._userAgent stays the empty string, and every outgoing request goes out with an empty User-Agent header.

Replace the 19 'assert(SDKVersion.X != nil)' triggers across 13 files with '_ = SDKVersion.X' so the lazy registration fires regardless of build configuration. Same registration mechanism — only the trigger moves out of an @autoclosure.

Adds Tests/AuthFoundationTests/SDKVersionRegistrationTests.swift to pin the contract. Verified to fail in 'swift test -c release' before this change and pass after.

SDKVersion.userAgent is populated as a side effect of evaluating the
lazy 'static let' registration in each Version+*.swift. Every dereference
site is currently spelled 'assert(SDKVersion.X != nil)' — but Swift's
assert(_:) takes its condition as @autoclosure, which the optimizer
strips in -O builds. In Release builds the lazies never fire,
SDKVersion._userAgent stays the empty string, and every outgoing request
goes out with an empty User-Agent header.

Replace the 19 'assert(SDKVersion.X != nil)' triggers across 13 files
with '_ = SDKVersion.X' so the lazy registration fires regardless of
build configuration. Same registration mechanism — only the trigger
moves out of an @autoclosure.

Adds Tests/AuthFoundationTests/SDKVersionRegistrationTests.swift to pin
the contract. Verified to fail in 'swift test -c release' before this
change and pass after.
@AlexNachbaur

Copy link
Copy Markdown
Contributor

Thank you for this @RicardoKoch, I have pulled this commit into #283 and will close this issue.

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.

2 participants