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

Replace dict by Mapping on HTTPException.headers #2749

Merged
merged 2 commits into from
Nov 18, 2024
Merged

Conversation

rijenkii
Copy link
Contributor

@rijenkii rijenkii commented Nov 11, 2024

Summary

See also: fastapi/fastapi#12786

HTTP Headers cannot be represented by a dict, as they can have duplicate entries. Example: Set-Cookie.

As such type of starlette.exceptions.HTTPException's headers field should be typing.Mapping instead of dict, just like starlette.responses.Response's headers field:

class Response:
media_type = None
charset = "utf-8"
def __init__(
self,
content: typing.Any = None,
status_code: int = 200,
headers: typing.Mapping[str, str] | None = None,
media_type: str | None = None,
background: BackgroundTask | None = None,
) -> None:

Checklist

  • I understand that this PR may be closed in case there was no previous discussion. (This doesn't apply to typos!)
  • I've added a test for each change that was introduced, and I tried as much as possible to make a single atomic change.
  • I've updated the documentation accordingly.

@Kludex Kludex changed the title Fix type of HTTPException.headers Replace dict by Mapping on HTTPException.headers Nov 18, 2024
@Kludex Kludex merged commit cc1e2d7 into encode:master Nov 18, 2024
6 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.

2 participants