Skip to content

Normalize HAR httpVersion to match live runner's protocol format#3

Merged
marky224 merged 2 commits into
mainfrom
polish/normalize-har-protocol
May 2, 2026
Merged

Normalize HAR httpVersion to match live runner's protocol format#3
marky224 merged 2 commits into
mainfrom
polish/normalize-har-protocol

Conversation

@marky224
Copy link
Copy Markdown
Owner

@marky224 marky224 commented May 2, 2026

Summary

  • HAR parser now normalizes response.httpVersion so HAR-derived and Run-derived Reports show the same Protocol string format.
  • Mapping covers: Chromium's http/2.0, Firefox's HTTP/2.0, ALPN's h2, plus the h1 variants and h3 — all map to httpx's HTTP/1.1 / HTTP/2 / HTTP/3 form.
  • Unknown values pass through unchanged.
  • Cosmetic-only change. Report shape, 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.0 proved 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 matrix
  • ruff check . clean
  • ruff format --check . clean
  • mypy clean
  • After merge: re-render any HAR-source Report in the hosted demo and confirm Protocol shows HTTP/2 (or HTTP/1.1) instead of http/2.0 / http/1.1

🤖 Generated with Claude Code

marky224 and others added 2 commits May 2, 2026 14:04
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 marky224 merged commit 34e5359 into main May 2, 2026
14 checks passed
@marky224 marky224 deleted the polish/normalize-har-protocol branch May 2, 2026 19:23
@marky224 marky224 mentioned this pull request May 2, 2026
6 tasks
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.
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