Repository navigation
Conversation
…n-1 values The three setters now validate through _prepare_header: the name must pass isascii() before it is lowercased, the value is still coerced with str(), and a non-ASCII value must encode as Latin-1 or the helper raises ValueError. The method docs and the bugfix note describe that contract, including that the check covers encoding and leaves ASCII control characters and HTTP field syntax to the application and the server, and that set_headers keeps items already written when a later item fails. ASGI encodes extra-header names as ASCII and their values as Latin-1, and a Latin-1 failure while rendering headers now reports ISO-8859-1. The tests cover setter acceptance and rejection, partial set_headers updates, Latin-1 emission on WSGI and ASGI, and the render path for content_type, which does not go through the setters. Fixes falconry#2767
Header setters now reject values that cannot be encoded as Latin-1, so the ASGI fatal rendering test stores the header directly to keep exercising the render-time encoding failure path.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #2768 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 64 64
Lines 8099 8107 +8
Branches 1131 1133 +2
=========================================
+ Hits 8099 8107 +8 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Member
|
I'm sorry, but we cannot accept LLM-generated code changes from you because you cannot verify them. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary of Changes
The three setters now validate through _prepare_header: the name must pass isascii() before it is lowercased, the value is still coerced with str(), and a non-ASCII value must encode as Latin-1 or the helper raises ValueError. The method docs and the bugfix note describe that contract, including that the check covers encoding and leaves ASCII control characters and HTTP field syntax to the application and the server, and that set_headers keeps items already written when a later item fails. ASGI encodes extra-header names as ASCII and their values as Latin-1, and a Latin-1 failure while rendering headers now reports ISO-8859-1. The tests cover setter acceptance and rejection, partial set_headers updates, Latin-1 emission on WSGI and ASGI, and the render path for content_type, which does not go through the setters.
Response.set_header, append_header, and set_headers stored header names that are not US-ASCII, including characters that change under lowercasing, and stored values that cannot be encoded as Latin-1. On ASGI, a Latin-1 value in an extra header such as Set-Cookie then failed while the headers were encoded, and the error said that names and values must be ASCII. Those setters only applied str() to the value and lowercased the name. str() returns an existing string unchanged, so it never checked an encoding, and case folding happened before any check of the name. Ordinary ASGI headers were encoded as Latin-1, but each _extra_headers value was encoded with ascii, and the UnicodeEncodeError handler described that failure as an ASCII-only rule.
Related Issues
Fixes #2767
Pull Request Checklist
This is just a reminder about the most common mistakes. Please make sure that you tick all appropriate boxes. Reading our contribution guide at least once will save you a few review cycles!
If an item doesn't apply to your pull request, check it anyway to make it apparent that there's nothing to do.
tox.Not claimed:
toxwas not run locally forfalcon/asgi/response.pyandfalcon/response.py.Left unticked: nothing in this change to
falcon/asgi/response.pyandfalcon/response.pybacks it.Left unticked: nothing in this change to
falcon/asgi/response.pyandfalcon/response.pybacks it.docs/.Not claimed: the local test run for
falcon/asgi/response.pyandfalcon/response.pycould not complete in this environment.docs/.Not claimed:
docs/was not run locally either.versionadded,versionchanged, ordeprecateddirectives.Not claimed:
versionaddedwas not run locally either.docs/_newsfragments/, with the file name format{issue_number}.{fragment_type}.rst. (Runtox -e docs, and inspectdocs/_build/html/changes/in the browser to ensure it renders correctly.)Not claimed: this diff changes no changelog or release-note file.
Not claimed: the same reason as the box above applies.
If you have any questions to any of the points above, just submit and ask! This checklist is here to help you, not to deter you from contributing!
PR template inspired by the attrs project.
AI was used for assistance.