feat(static): add proper HEAD support and method filtering#2611
Open
alexchenai wants to merge 2 commits intofalconry:masterfrom
Open
feat(static): add proper HEAD support and method filtering#2611alexchenai wants to merge 2 commits intofalconry:masterfrom
HEAD support and method filtering#2611alexchenai wants to merge 2 commits intofalconry:masterfrom
Conversation
Fixes falconry#2337. Static routes now handle HEAD requests by returning all relevant headers (Content-Type, Content-Length, ETag, Last-Modified, Accept-Ranges) without opening a file stream for the response body. Unsupported HTTP methods (POST, PUT, PATCH, DELETE) now receive a 405 Method Not Allowed response, and OPTIONS responses correctly advertise GET, HEAD, and OPTIONS in the Allow header. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
HEAD support and method filtering
vytas7
requested changes
Mar 19, 2026
Member
vytas7
left a comment
There was a problem hiding this comment.
Hello @alexchenai, and thanks for this PR!
Why did you remove the PR template? We don't strictly require that if you know what you're doing, but in this case it would have been helpful.
I have resurrected it below your AI-generated summary, please go through the steps carefully.
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
Fixes #2337.
HEADrequests by returning all relevant headers (Content-Type,Content-Length,ETag,Last-Modified,Accept-Ranges) without opening a file stream for the response body. This avoids unnecessary file I/O for HEAD requests.POST,PUT,PATCH,DELETE) now receive a405 Method Not Allowedresponse with a properAllowheader.Allowheader inOPTIONSresponses now correctly lists all supported methods (GET,HEAD,OPTIONS) instead of justGET.Changes
falcon/routing/static.py: Added_ALLOWED_METHODSclass variable, method validation at the top of__call__, HEAD-specific handling that sets headers and closes the file without streaming, and updated OPTIONS to advertise all allowed methods.tests/test_static.py: Added tests for HEAD requests (normal + 304 Not Modified), 405 Method Not Allowed for unsupported methods, and OPTIONS returning all allowed methods.docs/_newsfragments/2337.newandimproved.rst: Towncrier changelog fragment.Test plan
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.docs/.docs/.versionadded,versionchanged, ordeprecateddirectives.docs/_newsfragments/, with the file name format{issue_number}.{fragment_type}.rst. (Runtox -e towncrier, and inspectdocs/_build/html/changes/in the browser to ensure it renders correctly.)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.