Middleware short circuit does not use app.api.cors setting
- Dominant language
- Python
- Stars
- 11.1k
- Forks
- 1k
- Avg merge
- 1d 22h
- Merged PRs (30d)
- 2
Description
chalice 1.29.0
Python 3.11.4
Windows 10.0.19045 Build 19045
```python
from chalice import Chalice, Response
app = Chalice(app_name='chalice-test')
app.api.cors = True
@app.middleware('http')
def middle(event, get_response):
return Response({'test': 123})
@app.route('/test')
def index():
return {'hello': 'world'}
```
Without the middleware, `/test` returns headers
- Access-Control-Allow-Origin: *
- Access-Control-Allow-Headers: Authorization,Content-Type,X-Amz-Date,X-Amz-Security-Token,X-Api-Key
With the middleware function, these headers are not set. Expected behavior is that CORS headers would be set app-wide when using `app.api.cors`. I cannot find anything in the docs indicating that CORS should not be set by middleware.
Contributor guide
Research direction
Start with the HTTP middleware entry point and the app.api.cors setting, reproducing the issue with the provided /test route and short-circuiting middleware. Trace how the normal route response receives CORS headers and compare it with the middleware response. Done means app.api.cors applies the expected CORS headers in both cases.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- aws, python
- Domain
- api, backend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100