Skip to content

Show HTTP reason phrases for HTTP/2 and HTTP/3 via lookup table (issue #7694) - #8424

Open
Larslllllll wants to merge 3 commits into
mitmproxy:mainfrom
Larslllllll:main
Open

Larslllllll wants to merge 3 commits into
mitmproxy:mainfrom
Larslllllll:main

Conversation

@Larslllllll

Copy link
Copy Markdown

Summary

Show reason phrases for HTTP/2 and HTTP/3 responses in the mitmweb flow view by looking them up from a status code table. These are not transmitted on the wire per RFC 7540 (HTTP/2) and RFC 9113 (HTTP/3), so a lookup table provides the human-readable reason.

Changes

  1. Added web/gen/status_codes.py: A Python script that converts mitmproxy/net/http/status_codes.py to a TypeScript status code → reason phrase mapping.
  2. Added web/src/js/statusCodes.ts: Generated TypeScript file with export const statusCodeReasons: Record<number, string>.
  3. Updated web/src/js/components/FlowView/HttpMessages.tsx:
    • Imported statusCodeReasons
    • Modified ResponseLine to show looked-up reason for HTTP/2 and HTTP/3
    • Added a title tooltip explaining the reason is looked up (not transmitted)
    • Kept original behavior for HTTP/1.x (shows transmitted reason)

Details

  • For HTTP/1.x: Shows the reason phrase as transmitted over the wire (existing behavior).
  • For HTTP/2 and HTTP/3: Looks up the reason from statusCodeReasons[status_code] since the wire format omits it.
  • The lookup table includes all standard and custom status codes defined in mitmproxy.
  • A tooltip explains: "Reason phrase not transmitted for HTTP/2 and HTTP/3; looked up from status code".

Testing

  • Verified the script generates correct TypeScript.
  • The generated file builds successfully.
  • UI changes display correctly in flow view.

Closes the RFC task from #7694.

Co-authored-by: web/gen/status_codes.py

…mitmproxy#7694)

Adds statusCodeReasons lookup table (auto-generated from status_codes.py) and uses it in
HttpMessages ResponseLine to show reason phrases for HTTP/2 and HTTP/3 responses.
These are looked up from the status code since HTTP/2 and HTTP/3 do not transmit
reason phrases on the wire. Includes a title tooltip explaining this.
@Marwan-verse

Marwan-verse commented Sep 25, 2026 •

Copy link
Copy Markdown

I fetched the PR head at f9210c5 and ran python -m py_compile web/gen/status_codes.py. There are three independent syntax errors: lines 18–19 split a raw string across physical lines; line 34 contains unescaped double quotes inside a double-quoted raw string; and the f-string at line 70 closes before {reason}. Suggested fixes: put the first regex on one physical line with an escaped newline, use a triple-quoted string for the second regex, and use single quotes around the f-string. After fixing syntax, change results to dict[str, str] at line 27 because its keys are constant names and generate_ts expects string keys. The GitHub review endpoint would not permit inline comments, so I have documented the exact locations here.

@Marwan-verse

Copy link
Copy Markdown

Correction: I could not add inline comments because GitHub's review endpoint was unavailable. The issues I found are at lines 18 and 70; both are described above, but there are no inline review comments.

This branch has not been deployed

No deployments
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