Skip to content

Make the order of headers deterministic when recording HAR files#7

Merged
mattt merged 3 commits intomattt:mainfrom
tikitu:deterministic-header-order
Jan 16, 2026
Merged

Make the order of headers deterministic when recording HAR files#7
mattt merged 3 commits intomattt:mainfrom
tikitu:deterministic-header-order

Conversation

@tikitu
Copy link
Contributor

@tikitu tikitu commented Jan 16, 2026

The Swift dictionarys URLRequest.allHTTPHeaderFields and URLResponse.allHeaderFields do not guarantee a particular order of header keys. This produces unnecessary churn in the HAR files when re-recording requests, as the headers change order nondeterministically. Sorting the headers eliminates the churn.

The tests are stochastic but they failed reliably in my development environment; I couldn't figure out how to produce a deterministic failure however. My swift --version output:

swift-driver version: 1.120.5 Apple Swift version 6.1.2 (swiftlang-6.1.2.1.2 clang-1700.0.13.5)
Target: arm64-apple-macosx15.0

AI disclosure: I used an LLM-based agent (copilot in VSCode, with the model Claude Sonnet 4.5) as part of my development process for this contribution.

I couldn't figure out how to *deterministically* reproduce the
issue, so these are stochastic. They fail 100% reliably in my
dev environment, but I have no idea whether that will be the case
elsewhere. For the record my output of `swift --version` is:

swift-driver version: 1.120.5 Apple Swift version 6.1.2 (swiftlang-6.1.2.1.2 clang-1700.0.13.5)
Target: arm64-apple-macosx15.0
@tikitu tikitu changed the title Make the order of headers in the HAR files deterministic Make the order of headers deterministic when recording HAR files Jan 16, 2026
@mattt
Copy link
Owner

mattt commented Jan 16, 2026

@tikitu This is absolutely the correct behavior. Thank you for contributing this change!

@mattt mattt merged commit c15f853 into mattt:main Jan 16, 2026
4 checks passed
@mattt
Copy link
Owner

mattt commented Jan 16, 2026

This is now available in 0.3.1.

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