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
This PR adds automatic OPTIONS request support for ASGI routes created with
@getand@postdecorators. This enables CORS preflight requests from browsers without requiring manual OPTIONS route definitions.Changes:
Automatic OPTIONS request support - Added automatic OPTIONS handling in
HttpHandlerthat returns204 No Contentwith basic CORS headers. CORS headers are also added to main responses (GET, POST) whenOriginis present in the request. This provides minimal CORS support: returns theOriginfrom the request, allows route methods, and theContent-Typeheader.Tests - Added parameterized test
test_options_requestto verify OPTIONS handling for both GET and POST routes.Documentation - Added a note about automatic OPTIONS support in ASGI documentation.
Result:
Browsers can now perform CORS preflight requests without manually defining OPTIONS routes. This provides basic CORS support for simple use cases.
Code examples:
OPTIONS requests are automatically handled for all routes created with
@getor@postdecorators:You can test OPTIONS requests using curl:
curl -X OPTIONS http://localhost:8000/health \ -H "Origin: http://example.com" -vResolves #2658
Type of change
Please delete options that are not relevant.
Checklist
just lintshows no errors)just test-coveragejust static-analysis