Skip to content

fix(http): identify downloads and verify conversion transport - #2830

Open
Jasper (jipeng6036-del) wants to merge 3 commits into
microsoft:mainfrom
jipeng6036-del:fix/http-identification-transport-pr6
Open

Jasper (jipeng6036-del) wants to merge 3 commits into
microsoft:mainfrom
jipeng6036-del:fix/http-identification-transport-pr6

Conversation

@jipeng6036-del

Copy link
Copy Markdown

Problem and fix

Fixes #2820.

The default Requests User-Agent can be rejected before Wikipedia's converter receives a response. Identify sessions created by MarkItDown as MarkItDown/<version> (https://github.com/microsoft/markitdown), retaining the existing Markdown-first Accept header. Caller-supplied sessions keep their own headers. This follows Wikimedia's descriptive User-Agent policy, without impersonating a browser.

Based on sushan5140's unmerged #2821. Both original commits are retained separately, with their original author/date and cherry-picked-from source SHAs:

  • 27e7316a2e07d705993b29bfce47162b1ffbf75f
  • 52b92e9ab7d9b25a8fbb4544c2d8e5cc987fed03

The additional commit adds four real HTTP transport regressions through the public MarkItDown.convert() entry: direct and redirected downloads, default identification, custom session headers, built-in HTML conversion, and Unicode content. The tests use a local HTTP server, with no mocked Requests transport or external network dependency. They extend the source PR's prepared-request header tests. Original authorship and a real Co-authored-by trailer are preserved.

Older related #1445 uses a bare client name, and #1849 uses a browser identity. This version retains #2821's version/contact identification and verifies the complete download/conversion path.

Verification

Baseline: 7482c092d9c0074a89803c9fdb63a969e7fe17fc. Candidate tested/final tree: a68ee954afeeeae358ff34fcc5a66d8d719ec5ae.

  • New transport tests: 2 fail / 2 pass on baseline → 4 pass on candidate. The baseline failures are the default direct/redirect requests returning 403; custom session controls pass on both.
  • Windows / Python 3.12.13, normal hatch test --python 3.12: 1133 passed, 48 skipped.
  • Clean Linux / Python 3.13, full core suite: 1125 passed, 56 skipped. The validation image includes ffmpeg and exiftool; runs were capped at two CPUs.
  • Both Windows and Linux: OCR 108 passed, MCP 21 passed.
  • pre-commit run --all-files: passed (Black 26.10.1). The original header assertion's formatting is included in the additional commit.
  • Optional scoped mypy: the same three existing diagnostics on baseline/candidate in the same environment, with no new diagnostics. This is not a claim of a clean repository-wide type check.
  • Actual MarkItDown().convert("https://en.wikipedia.org/wiki/Python_(programming_language)"): baseline raises HTTP 403; the built and installed candidate wheel succeeds with title Python (programming language) and 219,771 Markdown characters. The installed markitdown <url> -o <file> CLI also exits 0 and writes nonempty Markdown. No model/API service was used.
pytest -q packages/markitdown/tests/test_http_identification.py
cd packages/markitdown && hatch test --python 3.12

The live Wikipedia result is an observation from this environment, not a guarantee that every site's access policy accepts this identity. Hosted CI and its remaining Python/OS matrix are checked after submission and are separate from these local results.

AI assistance: Codex was used to implement and review the additional transport coverage, inspect the reused patch, and run the verification above.

Use a real local HTTP server to cover normal downloads, redirects, built-in
HTML conversion, Unicode content, and caller-supplied session headers.
Retain the two original identification commits from sushan5140 microsoft#2821:
27e7316 and
52b92e9.

Co-authored-by: Susan5140s <167346857+sushan5140@users.noreply.github.com>
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.

URL fetch sends default python-requests User-Agent, Wikipedia returns 403

2 participants