Skip to content

Commit 2febfab

Browse files
Improve compatibility with PyPI mirrors that include charset in content-type headers (#261)
* fix: make content-type checking more flexible for PyPI mirrors * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Update changelog * Update changelog --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent f2e9b51 commit 2febfab

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
66

77
## Unreleased
88

9+
### Fixed
10+
11+
- Fixed content-type header parsing to handle PyPI mirrors that include charset parameters.
12+
This improves compatibility with mirrors that return headers like `application/json; charset=utf-8`.
13+
[#261](https://github.com/pyodide/micropip/pull/261)
14+
915
## [0.11.0] - 2025/10/18
1016

1117
### Added

micropip/package_index.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -250,16 +250,14 @@ def _select_parser(
250250
"""
251251
Select the function to parse the response based on the content type.
252252
"""
253-
match content_type:
253+
main_content_type = content_type.split(";")[0].strip()
254+
255+
match main_content_type:
254256
case "application/vnd.pypi.simple.v1+json":
255257
return ProjectInfo.from_simple_json_api
256258
case "application/json":
257259
return ProjectInfo.from_json_api
258-
case (
259-
"application/vnd.pypi.simple.v1+html"
260-
| "text/html"
261-
| "text/html; charset=utf-8"
262-
):
260+
case "application/vnd.pypi.simple.v1+html" | "text/html":
263261
return partial(
264262
ProjectInfo.from_simple_html_api,
265263
pkgname=pkgname,

0 commit comments

Comments
 (0)