Title: Preserve bytes subclasses when encoding headers by AryanRG · Pull Request #300 · python-hyper/hpack · GitHub
Open Graph Title: Preserve bytes subclasses when encoding headers by AryanRG · Pull Request #300 · python-hyper/hpack
X Title: Preserve bytes subclasses when encoding headers by AryanRG · Pull Request #300 · python-hyper/hpack
Description: Encoder.encode() silently changes header names and values supplied as ordinary bytes subclasses. For example, a subclass containing b'custom-key' is encoded as the literal text b"b'custom-key'". A subclass dictionary key containing b':method' also stops being recognized as a pseudo-header. Use isinstance(value, bytes) in _to_bytes() to preserve the original bytes. This restores the subclass behavior that preceded the performance optimization in #276. Remove the two type ignores made unnecessary by the resulting type narrowing. Seven regression cases cover empty and non-UTF-8 bytes, exact wire encoding and decoding in both Huffman modes, and dictionary pseudo-header ordering. All seven fail on the original source. Independent validation also reproduced all seven failures using the original conversion function. Validation on macOS: Upstream baseline: 502 tests passed, 100% statement and branch coverage on Python 3.13.12. Candidate: 509 tests passed with 100% statement and branch coverage on Python 3.11.16, 3.12.15, 3.13.12 and 3.14.4. Ruff, strict mypy, git diff --check, check-manifest, wheel/sdist builds and twine check passed. HTML documentation build succeeded with the existing unresolved our github page target at docs/source/installation.rst:10. Existing Hypothesis initialization warnings remain. Independent validation: 8 focused tests, Ruff, mypy and whitespace checks passed. AI assistance was used to prepare the implementation and regression tests. This PR is a draft pending maintainer review. Hosted CI is not yet verified.
Open Graph Description: Encoder.encode() silently changes header names and values supplied as ordinary bytes subclasses. For example, a subclass containing b'custom-key' is encoded as the literal text b"b'...
X Description: Encoder.encode() silently changes header names and values supplied as ordinary bytes subclasses. For example, a subclass containing b'custom-key' is encoded as the literal text b&am...
Opengraph URL: https://github.com/python-hyper/hpack/pull/300
X: @github
Domain: github.com
IPv4 address: 140.82.113.4
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /:user_id/:repository/pull/:id/files(.:format) |
| route-controller | pull_requests |
| route-action | files |
| fetch-nonce | v2:b1419635-75f5-987f-f1c8-3c846b6bd8c4 |
| current-catalog-service-hash | ae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b |
| request-id | 91E0:115752:18AD8A2:21DB517:6B072C19 |
| html-safe-nonce | 270d8e1d60c1c617d4230f7daed6c7cc447b9daaf05b72671f95d549965813fb |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5MUUwOjExNTc1MjoxOEFEOEEyOjIxREI1MTc6NkIwNzJDMTkiLCJ2aXNpdG9yX2lkIjoiNTUxNTg0NzA3MzQ5NDY3NDQ1OCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 27aacbec17ccb89dc096414ba1513e5e246dbd4e8eb8ba4fd33a9bcda711c76e |
| hovercard-subject-tag | pull_request:4895155183 |
| github-keyboard-shortcuts | repository,pull-request-list,pull-request-conversation,pull-request-files-changed,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/python-hyper/hpack/pull/300/files |
| twitter:image | https://avatars.githubusercontent.com/u/51299383?s=400&v=4 |
| twitter:card | summary_large_image |
| og:image | https://avatars.githubusercontent.com/u/51299383?s=400&v=4 |
| og:image:alt | Encoder.encode() silently changes header names and values supplied as ordinary bytes subclasses. For example, a subclass containing b'custom-key' is encoded as the literal text b"b'... |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | d0534ce3ec0f37caea4f39713cbc8a6a509506c09c7ac30e8e3e2e15348bd9c1 |
| turbo-cache-control | no-preview |
| diff-view | unified |
| go-import | github.com/python-hyper/hpack git https://github.com/python-hyper/hpack.git |
| octolytics-dimension-user_id | 13035907 |
| octolytics-dimension-user_login | python-hyper |
| octolytics-dimension-repository_id | 33873218 |
| octolytics-dimension-repository_nwo | python-hyper/hpack |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 33873218 |
| octolytics-dimension-repository_network_root_nwo | python-hyper/hpack |
| turbo-body-classes | logged-out env-production page-responsive full-width |
| disable-turbo | true |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | a73ca0a5164c4669446bdffe239b0d7542ad735e |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
| Server | github.com |
| Content-Type | text/html; charset=utf-8 |
| Cache-Control | no-cache |
Viewport: width=device-width