Skip to content

fix: Make Headers subclass Mapping - #233

Merged
hoodmane merged 1 commit into
cloudflare:mainfrom
hoodmane:hoodmane/httpmessage-mapping
Aug 28, 2026
Merged

fix: Make Headers subclass Mapping#233
hoodmane merged 1 commit into
cloudflare:mainfrom
hoodmane:hoodmane/httpmessage-mapping

Conversation

@hoodmane

Copy link
Copy Markdown
Contributor

HTTPMessage implements all the methods needed to be considered a Mapping but it does not register itself as a mapping. If we try to construct a Flask response and pass an HTTPMessage as a header, it fails to construct because it expects either:

  1. a Mapping (in which case it iterates over mapping.items()), or
  2. an iterable of key/value pairs

If you iterate a Mapping directly, you only get the keys, so it doesn't work correctly because HTTPMessage isn't a Mapping.

I'm not really sure we should be using http.client.HTTPMessage at all here, I'd rather we had our own Headers class. But given we are using it I think this is a clear improvement.

@hoodmane
hoodmane force-pushed the hoodmane/httpmessage-mapping branch 2 times, most recently from 3bee1ad to af5df27 Compare August 27, 2026 22:31
Comment thread packages/runtime-sdk/tests/workerd-test/sdk/tests/test_sdk.py Outdated

@dom96 dom96 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed with Gyeongjae, approving to unblock

@hoodmane
hoodmane force-pushed the hoodmane/httpmessage-mapping branch from af5df27 to cc5823a Compare August 28, 2026 18:23
`HTTPMessage` implements all the methods needed to be considered a `Mapping` but
it does not register itself as a mapping. If we try to construct a Flask
response and pass an `HTTPMessage` as a header, it fails to construct because it
expects either:
1. a `Mapping` (in which case it iterates over mapping.items()), or
2. an iterable of key/value pairs

If you iterate a `Mapping` directly, you only get the keys, so it doesn't work
correctly because `HTTPMessage` isn't a `Mapping`
@hoodmane
hoodmane force-pushed the hoodmane/httpmessage-mapping branch from cc5823a to b9925ef Compare August 28, 2026 18:26
@hoodmane
hoodmane merged commit 2e0a47f into cloudflare:main Aug 28, 2026
15 checks passed
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.

3 participants