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

fix: #2196 - incorrect handling of mutable headers in ASGIResponse #2308

Merged
merged 4 commits into from
Sep 17, 2023

Conversation

provinzkraut
Copy link
Member

@provinzkraut provinzkraut commented Sep 16, 2023

Update ASGIResponse, Response and friends to address a few issues related to headers:

  • If encoded_headers were passed in at any point, they were mutated within responses, leading to a growing list of headers with every response
  • While mutating encoded_headers, the checks performed to assert a value was (not) already present, headers were not treated case-insensitive
  • Unnecessary work was performed while converting cookies / headers into an encoded headers list

This was fixed by:

  • Removing the use of and deprecate encoded_headers
  • Handling headers on ASGIResponse with MutableScopeHeaders, which allows for case-insensitive membership tests, .setdefault operations etc

Closes #2196.


Please review this one thoroughly as it changes some low level stuff that we don't want to break (=

Copy link
Contributor

@gsakkis gsakkis left a comment

Choose a reason for hiding this comment

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

LGTM 👍

with create_test_client(handler) as client:
response = client.get("/")
assert response.status_code == HTTP_200_OK
assert [h.lower() for h in response.headers.get_list("last-modified")] == ["foo"]
Copy link
Contributor

Choose a reason for hiding this comment

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

Is .lower() necessary here (and if yes why)?

Copy link
Member Author

Choose a reason for hiding this comment

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

It was necessary because initially these headers wouldn't be lowercased. I didn't even realise this was bug had been in there until you mentioned it, but it's now fixed anyway so this can go (=

Signed-off-by: Janek Nouvertné <25355197+provinzkraut@users.noreply.github.com>
Signed-off-by: Janek Nouvertné <25355197+provinzkraut@users.noreply.github.com>
Signed-off-by: Janek Nouvertné <25355197+provinzkraut@users.noreply.github.com>
Signed-off-by: Janek Nouvertné <25355197+provinzkraut@users.noreply.github.com>
@sonarcloud
Copy link

sonarcloud bot commented Sep 16, 2023

SonarCloud Quality Gate failed.    Quality Gate failed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

98.0% 98.0% Coverage
3.0% 3.0% Duplication

idea Catch issues before they fail your Quality Gate with our IDE extension sonarlint SonarLint

@github-actions
Copy link

Documentation preview will be available shortly at https://litestar-org.github.io/litestar-docs-preview/2308

@provinzkraut
Copy link
Member Author

Merging this even though there are some coverage misses. These should be addressed in a separate PR since they're unrelated to the changes being introduced here.

@provinzkraut provinzkraut merged commit 359fa32 into main Sep 17, 2023
17 of 18 checks passed
@provinzkraut provinzkraut deleted the fix-2196 branch September 17, 2023 08:12
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.

Bug: Setting response_headers on the app triggers exceptions
2 participants