Skip to content

Match HTTP1 connection options case-insensitively - #8523

Closed
hakarrr wants to merge 10 commits into
mitmproxy:mainfrom
hakarrr:fix/http1-connection-case
Closed

hakarrr wants to merge 10 commits into
mitmproxy:mainfrom
hakarrr:fix/http1-connection-case

Conversation

@hakarrr

@hakarrr hakarrr commented Oct 25, 2026

Copy link
Copy Markdown
Contributor

Description

HTTP/1 connection options are case-insensitive (RFC 9110, section 7.6.1), but connection_close() currently compares tokens against lowercase literals without normalizing them. As a result, Connection: Close or CLOSE does not close an HTTP/1.1 connection, and Connection: Keep-Alive does not keep an HTTP/1.0 connection open.

Normalize the tokens locally for the persistence decision. Keep close precedence, complete-token matching, original header values, and the generic header-token helper unchanged.

Add eight helper cases covering mixed/uppercase options, HTTP/1.0 keep-alive, repeated fields, close precedence, header nonmutation, and lookalike tokens. Add six HTTP/1 client/server Playbook regressions that assert the actual CloseConnection command. Thirteen of the fourteen new cases fail without the source fix; the lookalike-token control already passes.

Validation on main 6debf65b612abc726fe9cabe5c2a1ebb1cb36df4:

  • uv run pytest test/mitmproxy/net/http/http1 test/mitmproxy/proxy/layers/http: 260 passed.
  • Broader test/mitmproxy --ignore=test/mitmproxy/tools: 1886 passed, 1 skipped, 1 environment failure creating a TUN device. The TUN failure also reproduces without the source fix.
  • Repository Ruff check and format check passed. Mypy for mitmproxy/net/http and mitmproxy/proxy passed (46 source files).

RFC: https://www.rfc-editor.org/rfc/rfc9110.html#section-7.6.1

Checklist

  • I have updated tests where applicable.
  • I have added an entry to the CHANGELOG.

@hakarrr

hakarrr commented Nov 13, 2026

Copy link
Copy Markdown
Contributor Author

Could a maintainer give this HTTP/1 connection-option case fix a human review and advise on the next step? The earlier autofix-job question in #8522 also covered this PR. Please let me know if changes are needed or if you'd prefer it closed. Thanks.

@hakarrr hakarrr closed this Nov 17, 2026
@hakarrr
hakarrr deleted the fix/http1-connection-case branch November 25, 2026 06:25
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