Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support multiple identical header fields in http responses "On Air" #1661

Merged
merged 5 commits into from
Sep 22, 2023

Conversation

rodja
Copy link
Member

@rodja rodja commented Sep 21, 2023

While working on #1603 it was discovered that we do not yet allow multiple 'set-cookie' entries in the header fields. This PR fixes that by transferring the response headers as list of tuples instead a dict.

to allow multiple 'set-cookie' entries
@rodja rodja added the enhancement New feature or request label Sep 21, 2023
@rodja rodja added this to the 1.3.15 milestone Sep 21, 2023
Copy link
Contributor

@falkoschindler falkoschindler left a comment

Choose a reason for hiding this comment

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

@rodja I'm not sure if this does exactly what you intended to. Your comment sounded like you're expecting the headers with duplicate keys to be transmitted as a list of tuples like

[('a', '1'), ('b', '2'), ('c', '3'), ('c', '42')]

But instead items() generates tuples like

[('a', '1'), ('b', '2'), ('c', '3, 42')]

I'm not yet sure if this works with the server implementation.

@rodja
Copy link
Member Author

rodja commented Sep 22, 2023

Thanks @falkoschindler. We need to use the .raw property to get all items:

import httpx

headers = httpx.Headers([(b'test', b'A'), (b'test', b'B')])
print([(k.decode(), v.decode()) for k, v in headers.raw])

I've already pushed the update to this PR.

Copy link
Contributor

@falkoschindler falkoschindler left a comment

Choose a reason for hiding this comment

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

headers.raw was still wrong. I guess you meant response.headers.raw.
But we can use response.headers.multi_items() instead, which does the list comprehension and decoding for us.

@falkoschindler falkoschindler merged commit dad7729 into main Sep 22, 2023
5 checks passed
@falkoschindler falkoschindler deleted the air_cookies branch September 22, 2023 06:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants