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

AsgiSetter should override header values instead of appending #1210

Open
phillipuniverse opened this issue Aug 1, 2022 · 0 comments
Open
Labels
bug Something isn't working

Comments

@phillipuniverse
Copy link
Contributor

phillipuniverse commented Aug 1, 2022

Describe your environment

Using FastAPI 0.79 and relying on the AsgiSetter. The AsgiSetter has a surprising result to always append values instead of overriding previous keys.

class ASGISetter(Setter[dict]):
def set(
self, carrier: dict, key: str, value: str
) -> None: # pylint: disable=no-self-use
"""Sets response header values on an ASGI scope according to `the spec <https://asgi.readthedocs.io/en/latest/specs/www.html#response-start-send-event>`_.
Args:
carrier: ASGI scope object
key: response header name to set
value: response header value
Returns:
None
"""
headers = carrier.get("headers")
if not headers:
headers = []
carrier["headers"] = headers
headers.append([key.lower().encode(), value.encode()])
asgi_setter = ASGISetter()

Steps to reproduce

Call AsgiSetter().set() multiple times with the same header name.

What is the expected behavior?

The 2nd call with the same header appends to the previous header value.

What is the actual behavior?
The result will be multiple headers with the same name are added instead of a single header with multiple values.

Additional context

Originally added by me (😬 ) at #817. It's also not 100% clear what the right behavior should be. Need to investigate the ASGI spec and what happens with multiple tuples with the same header name.

@phillipuniverse phillipuniverse added the bug Something isn't working label Aug 1, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant