Normalize HAR httpVersion to match live runner's protocol format#3
Merged
Conversation
Browser HARs disagree on the httpVersion string format: - Chromium writes 'http/2.0' (lowercase, with .0) - Firefox writes 'HTTP/2.0' (uppercase, with .0) - Some tools use the ALPN identifier 'h2' httpx's response.http_version is always 'HTTP/1.1' or 'HTTP/2' (uppercase, no .0 on h2). The Report's response.protocol field was therefore visually inconsistent depending on whether the surface that produced it was parse_har (passed through verbatim) or the live runner (httpx-formatted). Add _normalize_http_version that maps the common HAR variants to the runner's form and apply it at the parse_har call site. Unknown values pass through unchanged — better to display a surprising value than to misrepresent it. None / empty defaults to HTTP/1.1 to preserve the prior fallback. 11 tests cover the matrix (parametrized): http/2.0, HTTP/2.0, http/2, h2, http/1.1, HTTP/1.1, http/1.0, h3, http/3.0, plus unknown-passthrough and missing-defaults-to-1.1. Cosmetic-only — no Report shape change, schema_version unchanged, no engine logic touched. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
…s-through Self-review of #3 turned up an edge: whitespace-only input (' ') fell through the truthy check, then the lookup missed (strip+lower made it ''), and the function returned the raw whitespace string. That would have rendered as literal whitespace in the Protocol cell of the Report. Now the strip happens first; whitespace-only input takes the same HTTP/1.1 default as empty/None. Pass-through for unknown values also returns the stripped form so leading/trailing whitespace doesn't leak through that path either. Three additional tests cover whitespace-only input, trailing whitespace on a recognised value, and trailing whitespace on the unknown-value pass-through. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
marky224
added a commit
that referenced
this pull request
May 2, 2026
HAR-tab UX polish, Report action wiring, and parser hardening rolled up from PRs #2, #3, and the action-button work on this branch: - HAR picker meta line shows file size, capture date, unique-host count - Report Re-run / Export markdown buttons wired up (previously inert) - Lambda /api/analyze returns 400 with detail on malformed HAR entries - HAR parser distinguishes missing/wrong-type/empty for method+url - HAR httpVersion normalized to match live runner's protocol format schema_version stays at 1.0 — no Report shape changes.
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
response.httpVersionso HAR-derived and Run-derived Reports show the same Protocol string format.http/2.0, Firefox'sHTTP/2.0, ALPN'sh2, plus the h1 variants and h3 — all map to httpx'sHTTP/1.1/HTTP/2/HTTP/3form.schema_version, and engine logic are untouched.This was surfaced while diagnosing a "Body 0 B / Protocol http/2.0" report a user thought came from the Run tab — the lowercase
http/2.0proved it was HAR-derived. After this PR the strings won't disagree, so that diagnostic shortcut goes away (intentionally).Test plan
pytest— 346 passed, including 11 new parametrized cases covering the full normalization matrixruff check .cleanruff format --check .cleanmypycleanHTTP/2(orHTTP/1.1) instead ofhttp/2.0/http/1.1🤖 Generated with Claude Code